Commit dc86ef55 authored by Adam Blank's avatar Adam Blank
Browse files

Initial commit

parents
No related merge requests found
Showing with 101 additions and 0 deletions
+101 -0
gdb -q -x get_backtrace.py $1 | grep "^#" | grep -v "#0" | sed -e "s/ in.*//" | sed -e "s/^#[0-9]* //" | head -n -1
CC = gcc
CFLAGS = -g -fno-omit-frame-pointer
all: test
test: bt-test
bash -c "diff <(./answer ./bt-test) <(./run ./bt-test)"
bt-test: test.c bt.c
$(CC) $(CFLAGS) $^ -o $@
clean:
rm -f bt-test
gdb -q -nx -x get_backtrace.py $1 | grep "^#" | grep -v "#0" | sed -e "s/ in.*//" | sed -e "s/^#[0-9]* //"
#include <stdlib.h>
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include "bt.h"
bool is_stack_address(void *addr) {
return ((long)addr >> 40) == 0x7f;
}
void backtrace() {
char arr[0];
// TODO (student): FIXME...this does not look right.
void *rsp = NULL;
while (is_stack_address(rsp)) {
// TODO (student): Figure out what %rip is and print it out in a loop
void *rip = NULL;
printf("0x%016lx\n", (long)rip);
return;
}
}
#ifndef __BT_H
void backtrace();
#endif /* __BT_H */
gdb.execute("set confirm off")
gdb.execute("set pagination off")
gdb.execute("b backtrace")
gdb.execute("r")
gdb.execute("bt")
gdb.execute("c")
gdb.execute("q")
$1 | grep "^0x" | head -n -1
#include <stdlib.h>
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include "bt.h"
int maybe(int a) {
int arr[5];
(void)arr;
backtrace();
return a + 5;
}
int call_me(int a) {
int arr[100];
return maybe(a + arr[0]);
}
int main() {
call_me(1);
}
a.
b.
c.
d.
e.
2.
| Thread 1 | Thread 2|
| -------- | ------- |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
3.
4.
a.
b.
c.
d.
e.
6.
7.
8.
9.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment