forked from KolibriOS/kolibrios
debugger info, big stack opt
git-svn-id: svn://kolibrios.org@6441 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
7da05771e2
commit
227eb8887f
@ -27,6 +27,21 @@ extern "C" {
|
||||
#define TYPE_3_BORDER_WIDTH 5
|
||||
#define WIN_STATE_MINIMIZED 0x02
|
||||
#define WIN_STATE_ROLLED 0x04
|
||||
#define POS_SCREEN 0
|
||||
#define POS_WINDOW 1
|
||||
|
||||
#define IPC_NOBUFFER 1
|
||||
#define IPC_LOCKED 2
|
||||
#define IPC_OVERFLOW 3
|
||||
#define IPC_NOPID 4
|
||||
|
||||
#define SHM_OPEN 0x00
|
||||
#define SHM_OPEN_ALWAYS 0x04
|
||||
#define SHM_CREATE 0x08
|
||||
#define SHM_READ 0x00
|
||||
#define SHM_WRITE 0x01
|
||||
|
||||
|
||||
|
||||
typedef unsigned int color_t;
|
||||
|
||||
@ -63,6 +78,60 @@ typedef struct
|
||||
int out_size;
|
||||
}ioctl_t;
|
||||
|
||||
typedef union
|
||||
{
|
||||
struct
|
||||
{
|
||||
void *data;
|
||||
size_t size;
|
||||
} x;
|
||||
unsigned long long raw;
|
||||
}ufile_t;
|
||||
|
||||
struct kolibri_system_colors {
|
||||
color_t frame_area;
|
||||
color_t grab_bar;
|
||||
color_t grab_bar_button;
|
||||
color_t grab_button_text;
|
||||
color_t grab_text;
|
||||
color_t work_area;
|
||||
color_t work_button;
|
||||
color_t work_button_text;
|
||||
color_t work_text;
|
||||
color_t work_graph;
|
||||
};
|
||||
|
||||
|
||||
struct blit_call
|
||||
{
|
||||
int dstx;
|
||||
int dsty;
|
||||
int w;
|
||||
int h;
|
||||
|
||||
int srcx;
|
||||
int srcy;
|
||||
int srcw;
|
||||
int srch;
|
||||
|
||||
void *bitmap;
|
||||
int stride;
|
||||
};
|
||||
|
||||
struct ipc_message
|
||||
{
|
||||
uint32_t pid; // PID of sending thread
|
||||
uint32_t datalen; // data bytes
|
||||
char data[0]; // data begin
|
||||
};
|
||||
|
||||
struct ipc_buffer
|
||||
{
|
||||
uint32_t lock; // nonzero is locked
|
||||
uint32_t used; // used bytes in buffer
|
||||
struct ipc_message data[0]; // data begin
|
||||
};
|
||||
|
||||
static inline void begin_draw(void)
|
||||
{
|
||||
__asm__ __volatile__(
|
||||
@ -155,26 +224,6 @@ uint32_t get_skin_height(void)
|
||||
return height;
|
||||
};
|
||||
|
||||
/*
|
||||
// TinyC dont support aliasing of static inline funcs
|
||||
static inline void BeginDraw(void) __attribute__ ((alias ("begin_draw")));
|
||||
static inline void EndDraw(void) __attribute__ ((alias ("end_draw")));
|
||||
static inline void DrawWindow(int x, int y, int w, int h, const char *name,
|
||||
color_t workcolor, uint32_t style)
|
||||
__attribute__ ((alias ("sys_create_window")));
|
||||
static inline void DefineButton(void) __attribute__ ((alias ("define_button")));
|
||||
static inline void DrawLine(int xs, int ys, int xe, int ye, color_t color)
|
||||
__attribute__ ((alias ("draw_line")));
|
||||
static inline void DrawBar(int x, int y, int w, int h, color_t color)
|
||||
__attribute__ ((alias ("draw_bar")));
|
||||
static inline void DrawBitmap(void *bitmap, int x, int y, int w, int h)
|
||||
__attribute__ ((alias ("draw_bitmap")));
|
||||
static inline uint32_t GetSkinHeight(void) __attribute__ ((alias ("get_skin_height")));
|
||||
*/
|
||||
|
||||
#define POS_SCREEN 0
|
||||
#define POS_WINDOW 1
|
||||
|
||||
static inline
|
||||
pos_t get_mouse_pos(int origin)
|
||||
{
|
||||
@ -243,15 +292,6 @@ static inline int destroy_cursor(uint32_t cursor)
|
||||
return ret;
|
||||
};
|
||||
|
||||
/*
|
||||
static inline pos_t GetMousePos(int origin) __attribute__ ((alias ("get_mouse_pos")));
|
||||
static inline uint32_t GetMouseButtons(void) __attribute__ ((alias ("get_mouse_buttons")));
|
||||
static inline uint32_t GetMouseWheels(void) __attribute__ ((alias ("get_mouse_wheels")));
|
||||
|
||||
static inline uint32_t LoadCursor(void *path, uint32_t flags) __attribute__ ((alias ("load_cursor")));
|
||||
static inline uint32_t SetCursor(uint32_t cursor) __attribute__ ((alias ("set_cursor")));
|
||||
static inline int DestroyCursor(uint32_t cursor) __attribute__ ((alias ("destroy_cursor")));
|
||||
*/
|
||||
|
||||
static inline
|
||||
uint32_t wait_for_event(uint32_t time)
|
||||
@ -283,7 +323,6 @@ static inline uint32_t get_os_event()
|
||||
:"a"(10));
|
||||
return val;
|
||||
};
|
||||
//static inline uint32_t GetOsEvent(void) __attribute__ ((alias ("get_os_event")));
|
||||
|
||||
static inline
|
||||
uint32_t get_tick_count(void)
|
||||
@ -416,23 +455,6 @@ int *user_unmap(void *base, size_t offset, size_t size)
|
||||
return val;
|
||||
};
|
||||
|
||||
/*
|
||||
static inline void *UserAlloc(size_t size) __attribute__ ((alias ("user_alloc")));
|
||||
static inline int UserFree(void *mem) __attribute__ ((alias ("user_free")));
|
||||
static inline void* UserRealloc(void *mem, size_t size) __attribute__ ((alias ("user_realloc")));
|
||||
static inline int *UserUnmap(void *base, size_t offset, size_t size) __attribute__ ((alias ("user_unmap")));
|
||||
*/
|
||||
|
||||
typedef union
|
||||
{
|
||||
struct
|
||||
{
|
||||
void *data;
|
||||
size_t size;
|
||||
} x;
|
||||
unsigned long long raw;
|
||||
}ufile_t;
|
||||
|
||||
static inline ufile_t load_file(const char *path)
|
||||
{
|
||||
ufile_t uf;
|
||||
@ -444,7 +466,6 @@ static inline ufile_t load_file(const char *path)
|
||||
|
||||
return uf;
|
||||
};
|
||||
//static inline ufile_t LoadFile(const char *path) __attribute__ ((alias ("load_file")));
|
||||
|
||||
static inline int GetScreenSize()
|
||||
{
|
||||
@ -466,24 +487,6 @@ static inline void get_proc_info(char *info)
|
||||
:"a"(9), "b"(info), "c"(-1)
|
||||
:"memory");
|
||||
};
|
||||
//static inline void GetProcInfo(char *info) __attribute__ ((alias ("get_proc_info")));
|
||||
|
||||
|
||||
struct blit_call
|
||||
{
|
||||
int dstx;
|
||||
int dsty;
|
||||
int w;
|
||||
int h;
|
||||
|
||||
int srcx;
|
||||
int srcy;
|
||||
int srcw;
|
||||
int srch;
|
||||
|
||||
void *bitmap;
|
||||
int stride;
|
||||
};
|
||||
|
||||
static inline void Blit(void *bitmap, int dst_x, int dst_y,
|
||||
int src_x, int src_y, int w, int h,
|
||||
@ -507,6 +510,9 @@ static inline void Blit(void *bitmap, int dst_x, int dst_y,
|
||||
::"a"(73),"b"(0),"c"(&bc.dstx));
|
||||
};
|
||||
|
||||
|
||||
// newlib exclusive
|
||||
#ifndef __TINYC__
|
||||
int create_thread(int (*proc)(void *param), void *param, int stack_size);
|
||||
|
||||
void* load_library(const char *name);
|
||||
@ -516,7 +522,7 @@ void* get_proc_address(void *handle, const char *proc_name);
|
||||
void enumerate_libraries(int (*callback)(void *handle, const char* name,
|
||||
uint32_t base, uint32_t size, void *user_data),
|
||||
void *user_data);
|
||||
|
||||
#endif
|
||||
|
||||
// May be next section need to be added in newlibc
|
||||
|
||||
@ -577,19 +583,6 @@ int kol_clip_unlock()
|
||||
return val;
|
||||
}
|
||||
|
||||
struct kolibri_system_colors {
|
||||
color_t frame_area;
|
||||
color_t grab_bar;
|
||||
color_t grab_bar_button;
|
||||
color_t grab_button_text;
|
||||
color_t grab_text;
|
||||
color_t work_area;
|
||||
color_t work_button;
|
||||
color_t work_button_text;
|
||||
color_t work_text;
|
||||
color_t work_graph;
|
||||
};
|
||||
|
||||
static inline void get_system_colors(struct kolibri_system_colors *color_table)
|
||||
{
|
||||
__asm__ volatile ("int $0x40"
|
||||
@ -674,6 +667,55 @@ static inline int get_current_folder(char* buf, int bufsize){
|
||||
return val;
|
||||
}
|
||||
|
||||
static inline
|
||||
void ipc_set_area(void* buf, int bufsize){
|
||||
asm volatile ("int $0x40"::"a"(60), "b"(1), "c"(buf), "d"(bufsize));
|
||||
}
|
||||
|
||||
static inline
|
||||
int ipc_send_message(int pid_reciever, void *data, int datalen) {
|
||||
register int val;
|
||||
asm volatile ("int $0x40":"=a"(val):"a"(60), "b"(2), "c"(pid_reciever), "d"(data), "S"(datalen));
|
||||
return val;
|
||||
}
|
||||
|
||||
static inline
|
||||
void* shm_open(char *shm_name, int msize, int flags, int *retsz){
|
||||
register int val, cod;
|
||||
asm volatile ("int $0x40":"=a"(val),"=d"(cod):"a"(68), "b"(22), "c"(shm_name), "d"(msize), "S"(flags));
|
||||
|
||||
if(retsz) *retsz = cod; // errcode if NULL or memsize when open
|
||||
return (void*)val;
|
||||
}
|
||||
|
||||
static inline
|
||||
void shm_close(char *shm_name){
|
||||
asm volatile ("int $0x40"::"a"(68), "b"(23), "c"(shm_name));
|
||||
}
|
||||
|
||||
static inline
|
||||
int start_app(char *app_name, char *args){
|
||||
struct file_op_t
|
||||
{
|
||||
uint32_t fn;
|
||||
uint32_t flags;
|
||||
char* args;
|
||||
uint32_t res1, res2;
|
||||
char zero;
|
||||
char* app_name __attribute__((packed));
|
||||
} file_op;
|
||||
memset(&file_op, 0, sizeof(file_op));
|
||||
file_op.fn = 7;
|
||||
file_op.args = args;
|
||||
file_op.app_name = app_name;
|
||||
|
||||
register int val;
|
||||
asm volatile ("int $0x40":"=a"(val):"a"(70), "b"(&file_op));
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
static inline char *getcwd(char *buf, size_t size)
|
||||
{
|
||||
@ -713,6 +755,38 @@ void __attribute__ ((noinline)) debug_board_printf(const char *format,...)
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
// TinyC don't support aliasing of static inline funcs
|
||||
#ifndef __TINYC__
|
||||
static inline void BeginDraw(void) __attribute__ ((alias ("begin_draw")));
|
||||
static inline void EndDraw(void) __attribute__ ((alias ("end_draw")));
|
||||
static inline void DrawWindow(int x, int y, int w, int h, const char *name,
|
||||
color_t workcolor, uint32_t style)
|
||||
__attribute__ ((alias ("sys_create_window")));
|
||||
static inline void DefineButton(void) __attribute__ ((alias ("define_button")));
|
||||
static inline void DrawLine(int xs, int ys, int xe, int ye, color_t color)
|
||||
__attribute__ ((alias ("draw_line")));
|
||||
static inline void DrawBar(int x, int y, int w, int h, color_t color)
|
||||
__attribute__ ((alias ("draw_bar")));
|
||||
static inline void DrawBitmap(void *bitmap, int x, int y, int w, int h)
|
||||
__attribute__ ((alias ("draw_bitmap")));
|
||||
static inline uint32_t GetSkinHeight(void) __attribute__ ((alias ("get_skin_height")));
|
||||
static inline pos_t GetMousePos(int origin) __attribute__ ((alias ("get_mouse_pos")));
|
||||
static inline uint32_t GetMouseButtons(void) __attribute__ ((alias ("get_mouse_buttons")));
|
||||
static inline uint32_t GetMouseWheels(void) __attribute__ ((alias ("get_mouse_wheels")));
|
||||
static inline uint32_t LoadCursor(void *path, uint32_t flags) __attribute__ ((alias ("load_cursor")));
|
||||
static inline uint32_t SetCursor(uint32_t cursor) __attribute__ ((alias ("set_cursor")));
|
||||
static inline int DestroyCursor(uint32_t cursor) __attribute__ ((alias ("destroy_cursor")));
|
||||
static inline uint32_t GetOsEvent(void) __attribute__ ((alias ("get_os_event")));
|
||||
static inline void *UserAlloc(size_t size) __attribute__ ((alias ("user_alloc")));
|
||||
static inline int UserFree(void *mem) __attribute__ ((alias ("user_free")));
|
||||
static inline void* UserRealloc(void *mem, size_t size) __attribute__ ((alias ("user_realloc")));
|
||||
static inline int *UserUnmap(void *base, size_t offset, size_t size) __attribute__ ((alias ("user_unmap")));
|
||||
static inline ufile_t LoadFile(const char *path) __attribute__ ((alias ("load_file")));
|
||||
static inline void GetProcInfo(char *info) __attribute__ ((alias ("get_proc_info")));
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -92,6 +92,8 @@ int vfprintf ( FILE * stream, const char * format, va_list arg );
|
||||
|
||||
extern int errno;
|
||||
/* errors codes from KOS, but minus */
|
||||
#ifndef E_SUCCESS
|
||||
|
||||
# define E_SUCCESS (0)
|
||||
# define E_UNSUPPORTED (-2)
|
||||
# define E_UNKNOWNFS (-3)
|
||||
@ -106,5 +108,11 @@ extern int errno;
|
||||
/* conversion errors */
|
||||
# define ERANGE (-20)
|
||||
# define EINVAL (-21)
|
||||
/* program run and pipe errors */
|
||||
# define E_NOMEM2 (-30)
|
||||
# define E_FILEFMT (-31)
|
||||
# define E_TOOMANY (-32)
|
||||
# define E_PARAM (-33)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -13,7 +13,7 @@ int main(void)
|
||||
buf[sizeof buf - 1] = 0;
|
||||
|
||||
if ((x=strtod(buf, 0)) != want)
|
||||
t_error("strtod(.11[...]1) got %a want %a\n", x, want);
|
||||
t_error("strtod(.11[...]1) got %.18f want %.18f\n", x, want);
|
||||
|
||||
printf("%s finished\n", __FILE__);
|
||||
return t_status;
|
||||
|
@ -346,9 +346,12 @@ int main()
|
||||
j = ((2 * j) >> 2) << 2;
|
||||
}
|
||||
|
||||
printf("%s finished\n", __FILE__);
|
||||
printf("\n %s finished\n", __FILE__);
|
||||
if (test_failed)
|
||||
{
|
||||
printf("\n %s FAILED\n", __FILE__);
|
||||
abort();
|
||||
}
|
||||
else
|
||||
exit(0);
|
||||
}
|
@ -5,4 +5,4 @@
|
||||
#define ONE_SOURCE
|
||||
|
||||
//#define COMMIT_4ad186c5ef61_IS_FIXED
|
||||
|
||||
//#define CONFIG_TCC_BCHECK
|
||||
|
@ -2012,7 +2012,8 @@ enum {
|
||||
TCC_OPTION_E,
|
||||
TCC_OPTION_MD,
|
||||
TCC_OPTION_MF,
|
||||
TCC_OPTION_x
|
||||
TCC_OPTION_x,
|
||||
TCC_OPTION_stack
|
||||
};
|
||||
|
||||
#define TCC_OPTION_HAS_ARG 0x0001
|
||||
@ -2073,6 +2074,7 @@ static const TCCOption tcc_options[] = {
|
||||
{ "MD", TCC_OPTION_MD, 0},
|
||||
{ "MF", TCC_OPTION_MF, TCC_OPTION_HAS_ARG },
|
||||
{ "x", TCC_OPTION_x, TCC_OPTION_HAS_ARG },
|
||||
{ "stack", TCC_OPTION_stack, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP},
|
||||
{ NULL, 0, 0 },
|
||||
};
|
||||
|
||||
@ -2394,6 +2396,11 @@ ST_FUNC int tcc_parse_args1(TCCState *s, int argc, char **argv)
|
||||
case TCC_OPTION_pipe:
|
||||
/* ignored */
|
||||
break;
|
||||
case TCC_OPTION_stack:
|
||||
#ifdef TCC_TARGET_MEOS
|
||||
s->pe_stack_size = strtoul(optarg+1, NULL, 10);
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
if (s->warn_unsupported) {
|
||||
unsupported_option:
|
||||
|
@ -19,6 +19,9 @@ otherwise (error) underscoring all symbols, not only cdecl
|
||||
-impossible using with mingw-gcc compiled lib, incompatible library format:
|
||||
.o is PE-format from gcc but ELF from tcc, may be linux-gcc does it ok
|
||||
-no symbols (mapfile) for debug, see howtodebugtcc
|
||||
-no debug info for -g (kos32 linker imperfection)
|
||||
-__fastcall incompatible with other compilers. now stack freed by caller.
|
||||
must fix i386-gen.c@490,572 (fixed in other branch https://github.com/mirror/tinycc)
|
||||
|
||||
|
||||
-using __attribute__((packed)) see test82. need naming struct twice as in kos32sys1.h
|
||||
@ -108,3 +111,38 @@ string.h
|
||||
strxfrm
|
||||
|
||||
|
||||
Status or libc tests
|
||||
|
||||
---FAILED---
|
||||
tstring - need to fix
|
||||
|
||||
|
||||
---NOT TESTED---
|
||||
no library fns realized
|
||||
qsort
|
||||
strtol
|
||||
time
|
||||
|
||||
---HANG---
|
||||
sscanf
|
||||
>TEST_F(0x1234p56) - no %a formats
|
||||
|
||||
|
||||
---STACK IS SMALL---
|
||||
tstring
|
||||
strtodlong
|
||||
use new -stack=1280000 option
|
||||
|
||||
|
||||
--other--
|
||||
fscanf
|
||||
-?scanf ignores width specs, '*' and [chars], cant read %a float
|
||||
-%n counts as parameter
|
||||
|
||||
snprintf
|
||||
-some format misturbances
|
||||
|
||||
ungetc
|
||||
-ungetc fails if filepos == 0 - no tricks
|
||||
|
||||
all file ops limited to 2Gb
|
||||
|
@ -113,6 +113,7 @@ static void help(void)
|
||||
" -soname set name for shared library to be used at runtime\n"
|
||||
" -static static linking\n"
|
||||
" -Wl,-opt[=val] set linker option (see manual)\n"
|
||||
" -stack=size set PE/KOS32 stack size\n"
|
||||
"Debugger options:\n"
|
||||
" -g generate runtime debug info\n"
|
||||
#ifdef CONFIG_TCC_BCHECK
|
||||
|
@ -43,6 +43,9 @@ typedef struct {
|
||||
meos_section_info* bss_sections;
|
||||
} me_info;
|
||||
|
||||
int tcc_output_dbgme(const char *filename, me_info* me);
|
||||
|
||||
|
||||
meos_section_info* findsection(me_info* me,int num)
|
||||
{
|
||||
meos_section_info* si;
|
||||
@ -67,7 +70,7 @@ meos_section_info* findsection(me_info* me,int num)
|
||||
void build_reloc(me_info* me)
|
||||
{
|
||||
int flag;
|
||||
Elf32_Rel *rel, *rel_, *rel_end;
|
||||
Elf32_Rel *rel = 0, *rel_ = 0, *rel_end = 0;
|
||||
Section *sr;
|
||||
meos_section_info* s;
|
||||
meos_section_info* ss;
|
||||
@ -111,7 +114,7 @@ void build_reloc(me_info* me)
|
||||
}
|
||||
rel=rel_;
|
||||
s=s->next;
|
||||
if (s==0)
|
||||
if (s==0) // what about multiple BSS sections ?
|
||||
{
|
||||
if (flag) break;
|
||||
s=me->data_sections;
|
||||
@ -152,6 +155,7 @@ void assign_addresses(me_info* me)
|
||||
if (strcmp(".bss",s->name)==0)
|
||||
{
|
||||
si=tcc_malloc(sizeof(meos_section_info));
|
||||
si->data=s->data;
|
||||
si->data_size=s->data_offset;
|
||||
si->next=me->bss_sections;
|
||||
si->sec_num=i;
|
||||
@ -177,7 +181,10 @@ void assign_addresses(me_info* me)
|
||||
si->sh_addr=addr;
|
||||
addr+=si->data_size;
|
||||
}
|
||||
if (me->s1->pe_stack_size < 4096)
|
||||
addr+=4096;
|
||||
else
|
||||
addr += me->s1->pe_stack_size;
|
||||
addr=(addr+4)&(~3);
|
||||
me->header.stack=addr;
|
||||
me->header.memory_size=addr;
|
||||
@ -245,6 +252,10 @@ int tcc_output_me(TCCState* s1,const char *filename)
|
||||
me.s1=s1;
|
||||
relocate_common_syms();
|
||||
assign_addresses(&me);
|
||||
|
||||
if (s1->do_debug)
|
||||
tcc_output_dbgme(filename, &me);
|
||||
|
||||
me.header.entry_point=tcc_find_symbol_me(&me,"start");
|
||||
me.header.params= tcc_find_symbol_me(&me,"__argv"); // <--
|
||||
me.header.argv= tcc_find_symbol_me(&me,"__path"); // <--
|
||||
@ -262,6 +273,14 @@ int tcc_output_me(TCCState* s1,const char *filename)
|
||||
fwrite(si->data,1,si->data_size,f);
|
||||
for (si=me.data_sections;si;si=si->next)
|
||||
fwrite(si->data,1,si->data_size,f);
|
||||
for (si=me.bss_sections;si;si=si->next)
|
||||
fwrite(si->data,1,si->data_size,f);
|
||||
/*
|
||||
if (me.bss_sections) // Siemargl testin, what we lose
|
||||
{
|
||||
tcc_error_noabort("We lose .BSS section when linking KOS32 executable");
|
||||
}
|
||||
*/
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
@ -288,3 +307,181 @@ char *getcwd(char *buf, size_t size)
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
static FILE *src_file;
|
||||
static int next_src_line;
|
||||
|
||||
void close_source_file()
|
||||
{
|
||||
if (src_file)
|
||||
fclose(src_file);
|
||||
src_file = NULL;
|
||||
}
|
||||
|
||||
void load_source_file(char *fname)
|
||||
{
|
||||
close_source_file();
|
||||
src_file = fopen(fname,"rt");
|
||||
if (!src_file) return;
|
||||
next_src_line = 1;
|
||||
}
|
||||
|
||||
int get_src_lines(char *buf, int sz, int start, int end)
|
||||
// 1 if read
|
||||
{
|
||||
char line[255], *ch;
|
||||
strcpy(buf, "");
|
||||
if (!src_file) return 0;
|
||||
while (next_src_line < start) // skip
|
||||
{
|
||||
ch = fgets(line, sizeof line, src_file);
|
||||
if (!ch) return 0;
|
||||
next_src_line++;
|
||||
}
|
||||
while (next_src_line <= end)
|
||||
{
|
||||
ch = fgets(line, sizeof line, src_file);
|
||||
if (!ch) return 0;
|
||||
next_src_line++;
|
||||
strncat(buf, line, sz - strlen(buf) - 1);
|
||||
}
|
||||
// remove newlines
|
||||
for (ch = buf; *ch; ch++)
|
||||
if (strchr("\t\n\r", *ch)) *ch = ' ';
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int tcc_output_dbgme(const char *filename, me_info* me)
|
||||
// by Siemargl. Writes filename.dbg file for source code level debuggin with MTDBG
|
||||
// return 1 on error
|
||||
{
|
||||
FILE *fdbg;
|
||||
char fname[400], buf[200];
|
||||
|
||||
strcpy(fname, filename);
|
||||
strcat(fname, ".dbg");
|
||||
fdbg = fopen(fname,"wt");
|
||||
if (!fdbg) return 1;
|
||||
|
||||
meos_section_info *si, *ss;
|
||||
fputs(".text\n", fdbg); // just for mtbg
|
||||
|
||||
// print symbol table with resolved addresses
|
||||
Elf32_Sym* esym;
|
||||
for (esym = (Elf32_Sym*)symtab_section->data; esym <= (Elf32_Sym*)(symtab_section->data + symtab_section->data_offset); esym++)
|
||||
{
|
||||
if (esym->st_info == 0 || esym->st_info == 4) continue;
|
||||
int sect = esym->st_shndx;
|
||||
ss = findsection(me, sect);
|
||||
const char *sym_name = strtab_section->data + esym->st_name;
|
||||
if (ss == 0)
|
||||
{
|
||||
fprintf(fdbg, "undefined symbol '%s' type(%d)\n", sym_name, esym->st_info);
|
||||
continue;
|
||||
}
|
||||
fprintf(fdbg, "0x%X %s\n", ss->sh_addr + esym->st_value, sym_name); // removed type(%d) esym->st_info
|
||||
}
|
||||
|
||||
fputs(".text source code links\n", fdbg); // just for mtbg
|
||||
// print symbol table with resolved addresses
|
||||
Stab_Sym *stab;
|
||||
char *str = "", *cur_file = "???", cur_fun[255];
|
||||
int cur_line = 0, cur_fun_addr = 0, fun_flag = 0;
|
||||
strcpy(cur_fun, "fn???");
|
||||
for (stab = (Stab_Sym*)stab_section->data; stab <= (Stab_Sym*)(stab_section->data + stab_section->data_offset); stab++)
|
||||
{
|
||||
str = "";
|
||||
switch(stab->n_type)
|
||||
{
|
||||
case 100: // source file, or path
|
||||
if (stab->n_strx)
|
||||
{
|
||||
cur_file = stabstr_section->data + stab->n_strx;
|
||||
load_source_file(cur_file);
|
||||
}
|
||||
else
|
||||
cur_file = "???";
|
||||
strcpy(cur_fun, "fn???");
|
||||
cur_line = 0;
|
||||
cur_fun_addr = 0;
|
||||
fun_flag = 0;
|
||||
break;
|
||||
case 36: // func
|
||||
cur_fun_addr = 0;
|
||||
if (stab->n_strx)
|
||||
{
|
||||
strcpy(cur_fun, stabstr_section->data + stab->n_strx);
|
||||
str = strchr(cur_fun, ':');
|
||||
if (str) *str = '\0';
|
||||
cur_fun_addr = tcc_find_symbol_me(me, cur_fun);
|
||||
cur_line = stab->n_desc;
|
||||
fun_flag = 1;
|
||||
//fprintf(fdbg, "0x%X %s() line(%d)\n", cur_fun_addr, cur_fun, cur_line); // commented as conflicted with direct address
|
||||
}
|
||||
else
|
||||
strcpy(cur_fun, "fn???");
|
||||
break;
|
||||
case 68: // N_SLINE
|
||||
if (stab->n_value == 0 ) continue; // skip zero offset line
|
||||
if (fun_flag) // skip string {, as duplicates address
|
||||
{
|
||||
fun_flag = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
int line;
|
||||
if (stab->n_desc > cur_line)
|
||||
line = cur_line + 1;
|
||||
else
|
||||
line = cur_line;
|
||||
//fprintf(fdbg, "0x%X LINES %d-%d \n", cur_fun_addr + stab->n_value, line, stab->n_desc);
|
||||
if (get_src_lines(buf, sizeof buf, line, stab->n_desc))
|
||||
fprintf(fdbg, "0x%X %s\n", cur_fun_addr + stab->n_value, buf);
|
||||
|
||||
cur_line = stab->n_desc;
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
/*
|
||||
if (stab->n_strx)
|
||||
str = stabstr_section->data + stab->n_strx;
|
||||
fprintf(fdbg, "0x%X type(%d) str(%s) desc(%d)\n", stab->n_value, stab->n_type, str, stab->n_desc);
|
||||
*/
|
||||
}
|
||||
|
||||
/* for(; si; si = si->next)
|
||||
{
|
||||
Section *sr;
|
||||
Elf32_Rel *rel, *rel_end;
|
||||
for(sr = me->s1->sections[si->sec_num]->reloc; sr; )
|
||||
{
|
||||
for (rel = (Elf32_Rel *) sr->data, rel_end = (Elf32_Rel *) (sr->data + sr->data_offset); rel < rel_end; rel++)
|
||||
{
|
||||
int type = ELF32_R_TYPE(rel->r_info);
|
||||
if (type != R_386_PC32 && type != R_386_32)
|
||||
continue;
|
||||
int sym = ELF32_R_SYM(rel->r_info);
|
||||
if (sym > symtab_section->data_offset / sizeof(Elf32_Sym))
|
||||
continue;
|
||||
Elf32_Sym* esym = ((Elf32_Sym*)symtab_section->data) + sym;
|
||||
int sect = esym->st_shndx;
|
||||
ss = findsection(me, sect);
|
||||
const char *sym_name = strtab_section->data + esym->st_name;
|
||||
if (ss == 0)
|
||||
{
|
||||
fprintf(fdbg, "undefined symbol '%s'\n", sym_name);
|
||||
continue;
|
||||
}
|
||||
if (rel->r_offset > si->data_size) continue;
|
||||
fprintf(fdbg, "\t0x%X %s\n", ss->sh_addr + esym->st_value, sym_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
close_source_file();
|
||||
fclose(fdbg);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user