1
0
mirror of https://github.com/ioacademy-jikim/debugging synced 2026-08-11 16:32:58 +00:00

first commit

This commit is contained in:
jikim
2015-12-13 22:34:58 +09:00
commit 0b589c7986
9455 changed files with 4350134 additions and 0 deletions
+4
View File
@@ -0,0 +1,4 @@
#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
void print_gnu_backtrace(void);
+21
View File
@@ -0,0 +1,21 @@
#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
void print_gnu_backtrace(void)
{
void * frame_addrs[16];
char** frame_strings;
size_t backtrace_size;
int i;
backtrace_size = backtrace( frame_addrs, 16 );
frame_strings = backtrace_symbols( frame_addrs, backtrace_size );
for( i=0; i<backtrace_size; ++i )
{
printf("%d: [0x%p] %s\n", i, frame_addrs[i], frame_strings[i] );
}
free( frame_strings );
}
+17
View File
@@ -0,0 +1,17 @@
#include <stdio.h>
typedef struct layout
{
struct layout* ebp;
void* ret;
} layout;
void print_gnu_backtrace()
{
layout* ebp = __builtin_frame_address(0);
while( ebp )
{
printf("0x%08x\n", (unsigned int)ebp->ret );
ebp = ebp->ebp;
}
}
+23
View File
@@ -0,0 +1,23 @@
#define _GNU_SOURCE
#include <stdio.h>
#include <dlfcn.h>
void **getEBP(int dummy)
{
void **ebp = (void**)&dummy - 2 ;
return (ebp);
}
void **save_ebp;
void print_gnu_backtrace(void)
{
int dummy;
void **ebp = getEBP(dummy);
void **ret = *(ebp + 1);
ebp = *ebp;
while(ebp)
{
printf("%p\n", ret );
ret = *(ebp + 1);
ebp = *ebp;
}
}
+29
View File
@@ -0,0 +1,29 @@
#define _GNU_SOURCE
#include <stdio.h>
#include <dlfcn.h>
void **getEBP(int dummy)
{
void **ebp = (void**)&dummy - 2 ;
return ebp;
}
void print_gnu_backtrace(void)
{
int dummy;
int frame = 0;
Dl_info dlip;
void **ebp = getEBP(dummy);
void **ret = *(ebp+1);
ebp = *ebp;
printf("Stack backtrace_3:\n");
while(ebp)
{
if( dladdr(ret, &dlip) == 0 )
break;
printf("Frame %d : [ebp=%p] [ret=%p] %s\n", frame++, ebp, ret, dlip.dli_sname );
ret = *(ebp + 1);
ebp = *ebp;
}
}
+24
View File
@@ -0,0 +1,24 @@
#define UNW_LOCAL_ONLY
#define _GNU_SOURCE
#include <libunwind.h>
#include <dlfcn.h>
#include "backtrace.h"
void print_gnu_backtrace (void) {
unw_word_t ip, sp;
unw_cursor_t cursor; unw_context_t uc;
Dl_info dlip;
int frame=0;
unw_getcontext(&uc);
unw_init_local(&cursor, &uc);
while (unw_step(&cursor) > 0) {
unw_get_reg(&cursor, UNW_REG_IP, &ip);
unw_get_reg(&cursor, UNW_REG_SP, &sp);
if( dladdr((void*)ip, &dlip) == 0 )
break;
printf("Frame %d : [ebp=%p] [ret=%p] %s\n", frame++,
(void*)sp, (void*)ip, dlip.dli_sname );
}
}
+24
View File
@@ -0,0 +1,24 @@
#define UNW_LOCAL_ONLY
#include <libunwind.h>
#include "backtrace.h"
void print_gnu_backtrace()
{
unw_cursor_t cursor;
unw_context_t context;
unw_getcontext(&context);
unw_init_local(&cursor, &context);
while (unw_step(&cursor) > 0) {
unw_word_t offset, pc;
char fname[64];
unw_get_reg(&cursor, UNW_REG_IP, &pc);
fname[0] = '\0';
(void) unw_get_proc_name(&cursor, fname, sizeof(fname), &offset);
printf ("%p : (%s+0x%x) [%p]\n", (void*)pc, fname, offset, (void*)pc);
}
}
+27
View File
@@ -0,0 +1,27 @@
#include "backtrace.h"
int foo(void)
{
print_gnu_backtrace();
return 0;
}
int bar(void)
{
foo();
return 0;
}
int boo(void)
{
bar();
return 0;
}
int baz(void)
{
boo();
return 0;
}
int main()
{
baz();
return 0;
}
Submodule 01_day/backtrace/libunwind added at 8afc33ce9f