-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1843 from ghaerr/debug
[debug] Rewrite stack tracing code, add disasm to distribution
- Loading branch information
Showing
15 changed files
with
206 additions
and
119 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ SUBDIRS = \ | |
basic \ | ||
bc \ | ||
busyelks \ | ||
debug \ | ||
disk_utils \ | ||
fsck_dos \ | ||
elvis \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
Possible ia16-elf-gcc function prologues | ||
---------------------------------------- | ||
|
||
SI only | ||
193: 56 push %si | ||
|
||
SI & DI only | ||
0: 56 push %si | ||
1: 57 push %di | ||
|
||
BASIC | ||
0: 55 push %bp | ||
1: 89 e5 mov %sp,%bp | ||
|
||
BASIC w/SI | ||
3d: 56 push %si | ||
3e: 55 push %bp | ||
3f: 89 e5 mov %sp,%bp | ||
|
||
BASIC w/SI & DI | ||
13e: 56 push %si | ||
13f: 57 push %di | ||
140: 55 push %bp | ||
141: 89 e5 mov %sp,%bp | ||
|
||
BASIC w/SI & DI and small locals | ||
1c4: 56 push %si | ||
1c5: 57 push %di | ||
1c6: 55 push %bp | ||
1c7: 89 e5 mov %sp,%bp | ||
1c9: 83 ec 24 sub $0x24,%sp | ||
|
||
BASIC w/SI & DI and large locals | ||
6d: 56 push %si | ||
6e: 57 push %di | ||
6f: 55 push %bp | ||
70: 89 e5 mov %sp,%bp | ||
72: 81 ec 84 00 sub $0x84,%sp | ||
|
||
Suggested algorithm: | ||
Search for 55 89 e5 in reverse order at IP-3 (BASIC), IP-6 (BASIC w/small locals) | ||
and IP-6 (BASIC w/large locals). | ||
If found, BP_PUSHED, IP=matched IP; | ||
Then search for 57 DI_PUSHED, --IP; | ||
then search for 56 SI_PUSHED, --IP; | ||
Last location (IP) is then function start. | ||
|
||
Use -finstrument-functions-simple. # function profiling | ||
Possibly use -fno-omit-frame-pointer. # alwaus push BP in prologue | ||
Possibly use -fno-optimize-sibling-calls. # disable tail call optimization |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* ELKS shared instrumentation functions for ia16-elf-gcc | ||
* | ||
* June 2022 Greg Haerr | ||
* Mar 2024 Added backwards scan w/o symbol table using _get_fn_start_address | ||
*/ | ||
#include <stdio.h> | ||
#include "instrument.h" | ||
#include "syms.h" | ||
|
||
#define _get_csbyte(ip) __extension__ ({ \ | ||
unsigned char _v; \ | ||
asm volatile ("mov %%cs:(%%bx),%%al" \ | ||
:"=Ral" (_v) \ | ||
:"b" (ip)); \ | ||
_v; }) | ||
|
||
/* | ||
* Calculate function start address containing addr. | ||
* Proper operation requires compilation with -fno-omit-frame-pointer | ||
* and -fno-optimize-sibling-calls. | ||
*/ | ||
int * noinstrument _get_fn_start_address(int *addr) | ||
{ | ||
char *ip = (char *)addr; | ||
int i = 0; | ||
|
||
/* adjust forward if addr is function start (hack) */ | ||
if (_get_csbyte(ip) == 0x56) { /* push %si */ | ||
i = -1; | ||
if (_get_csbyte(ip+1) == 0x57) /* push %di */ | ||
i = -2; | ||
} | ||
|
||
/* look backwards for prologue: push %bp/mov %sp,%bp (55 89 e5) */ | ||
for(;;) { | ||
/* main called at 0x37 from crt0.S which has no prologue at _start */ | ||
if ((unsigned int)ip-i <= 0x37) | ||
return 0; /* _start address or start address not found */ | ||
|
||
if (_get_csbyte(ip-i+0) == 0x55 && /* push %bp */ | ||
_get_csbyte(ip-i+1) == 0x89 && /* mov %sp,%bp */ | ||
_get_csbyte(ip-i+2) == 0xe5) { | ||
ip = ip - i; | ||
/* prologue possibly prededed by optional push %si/%di */ | ||
if ((i = _get_csbyte(ip-1)) == 0x57) /* push %di */ | ||
return (int *)(ip-2); /* start is push %si,push %di */ | ||
if (i == 0x56) /* push %si */ | ||
return (int *)(ip-1); /* start is push %si */ | ||
return (int *)ip; /* start is push %bp */ | ||
} | ||
i++; | ||
} | ||
} | ||
|
||
/* | ||
* Return pushed word count and register bitmask by function at passed address, | ||
* used to traverse BP chain and display registers. | ||
*/ | ||
int noinstrument _get_push_count(int *fnstart) | ||
{ | ||
char *fp = (char *)fnstart; | ||
int count = 0; | ||
|
||
int opcode = _get_csbyte(fp++); | ||
if (opcode == 0x56) /* push %si */ | ||
count = (count+1) | SI_PUSHED, opcode = _get_csbyte(fp++); | ||
if (opcode == 0x57) /* push %di */ | ||
count = (count+1) | DI_PUSHED, opcode = _get_csbyte(fp++); | ||
if (opcode == 0x55 || /* push %bp */ | ||
(opcode == 0x59 && (unsigned int)fp < 0x40)) /* hack for crt0.S 'pop %cx' start */ | ||
count = (count + 1) | BP_PUSHED, opcode = _get_csbyte(fp); | ||
//printf("%s (%x) pushes %x\n", sym_text_symbol(addr, 1), (int)addr, count); | ||
return count; | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.