diff options
Diffstat (limited to 'gcc/ada/gmem.c')
-rw-r--r-- | gcc/ada/gmem.c | 146 |
1 files changed, 56 insertions, 90 deletions
diff --git a/gcc/ada/gmem.c b/gcc/ada/gmem.c index fe9928c6918..c21fa47c8ff 100644 --- a/gcc/ada/gmem.c +++ b/gcc/ada/gmem.c @@ -4,7 +4,6 @@ * * * G M E M * * * - * * * C Implementation File * * * * Copyright (C) 2000-2003 Free Software Foundation, Inc. * @@ -41,46 +40,39 @@ NOTE: This capability is currently supported on the following targets: DEC Unix - SGI Irix GNU/Linux x86 Solaris (sparc and x86) (*) Windows 98/95/NT (x86) (*) on these targets, the compilation must be done with -funwind-tables to - be able to build the stack backtrace. */ - -#ifdef __alpha_vxworks -#include "vxWorks.h" -#endif - -#ifdef IN_RTS -#include "tconfig.h" -#include "tsystem.h" -#else -#include "config.h" -#include "system.h" -#endif + be able to build the stack backtrace. +*/ -#include "adaint.h" +#include <stdio.h> static FILE *gmemfile; /* tb_len is the number of call level supported by this module */ -#define TB_LEN 200 - -static char *tracebk[TB_LEN]; +#define tb_len 200 +static char * tracebk [tb_len]; static int cur_tb_len, cur_tb_pos; -static void gmem_read_backtrace PARAMS ((void)); -static char *spc2nul PARAMS ((char *)); +#define LOG_EOF '*' +#define LOG_ALLOC 'A' +#define LOG_DEALL 'D' + +struct struct_storage_elmt { + char Elmt; + void * Address; + size_t Size; +}; + +extern void +convert_addresses (char *addrs[], int n_addr, void *buf, int *len); -extern int __gnat_gmem_initialize PARAMS ((char *)); -extern void __gnat_gmem_a2l_initialize PARAMS ((char *)); -extern void __gnat_gmem_read_next PARAMS ((char *)); -extern void __gnat_gmem_read_bt_frame PARAMS ((char *)); - -/* Reads backtrace information from gmemfile placing them in tracebk - array. cur_tb_len is the size of this array. */ +/* reads backtrace information from gmemfile placing them in tracebk + array. cur_tb_len is the size of this array +*/ static void gmem_read_backtrace () @@ -90,20 +82,19 @@ gmem_read_backtrace () cur_tb_pos = 0; } -/* Initialize gmem feature from the dumpname file. Return 1 if the - dumpname has been generated by GMEM (instrumented malloc/free) and 0 if not - (i.e. probably a GDB generated file). */ +/* initialize gmem feature from the dumpname file. It returns 1 if the + dumpname has beed generated by GMEM (instrumented malloc/free) and 0 if not + (i.e. probably a GDB generated file). +*/ -int -__gnat_gmem_initialize (dumpname) - char *dumpname; +int __gnat_gmem_initialize (char *dumpname) { - char header[10]; + char header [10]; gmemfile = fopen (dumpname, "rb"); fread (header, 10, 1, gmemfile); - /* Check for GMEM magic-tag. */ + /* check for GMEM magic-tag */ if (memcmp (header, "GMEM DUMP\n", 10)) { fclose (gmemfile); @@ -113,53 +104,50 @@ __gnat_gmem_initialize (dumpname) return 1; } -/* Initialize addr2line library */ +/* initialize addr2line library */ -void -__gnat_gmem_a2l_initialize (exename) - char *exename; +void __gnat_gmem_a2l_initialize (char *exename) { extern char **gnat_argv; - char s[100]; + char s [100]; int l; - gnat_argv[0] = exename; + gnat_argv [0] = exename; convert_addresses (tracebk, 1, s, &l); } /* Read next allocation of deallocation information from the GMEM file and - write an alloc/free information in buf to be processed by GDB (see gnatmem - implementation). */ + write an alloc/free information in buf to be processed by gnatmem */ void __gnat_gmem_read_next (buf) - char *buf; + struct struct_storage_elmt *buf; { void *addr; - int size; + size_t size; int j; j = fgetc (gmemfile); if (j == EOF) { fclose (gmemfile); - sprintf (buf, "Program exited."); + buf->Elmt = LOG_EOF; } else { switch (j) { case 'A' : - fread (&addr, sizeof (char *), 1, gmemfile); - fread (&size, sizeof (int), 1, gmemfile); - sprintf (buf, "ALLOC^%d^0x%lx^", size, (long) addr); + buf->Elmt = LOG_ALLOC; + fread (&(buf->Address), sizeof (void *), 1, gmemfile); + fread (&(buf->Size), sizeof (size_t), 1, gmemfile); break; case 'D' : - fread (&addr, sizeof (char *), 1, gmemfile); - sprintf (buf, "DEALL^0x%lx^", (long) addr); + buf->Elmt = LOG_DEALL; + fread (&(buf->Address), sizeof (void *), 1, gmemfile); break; default: - puts ("GMEM dump file corrupt"); + puts ("GNATMEM dump file corrupt"); __gnat_os_exit (1); } @@ -167,48 +155,26 @@ __gnat_gmem_read_next (buf) } } -/* Scans the line until the space or new-line character is encountered; - this character is replaced by nul and its position is returned. */ +/* Read the next frame from the current traceback, and move the cursor to the + next frame */ -static char * -spc2nul (s) - char *s; +void __gnat_gmem_read_next_frame (void** addr) { - while (*++s) - if (*s == ' ' || *s == '\n') - { - *s = 0; - return s; - } - - abort (); + if (cur_tb_pos >= cur_tb_len) { + *addr = NULL; + } else { + *addr = (void*)*(tracebk + cur_tb_pos); + ++cur_tb_pos; + } } -/* Convert backtrace address in tracebk at position cur_tb_pos to a symbolic - traceback information returned in buf and to be processed by GDB (see - gnatmem implementation). */ +/* Converts addr into a symbolic traceback, and stores the result in buf + with a format suitable for gnatmem */ -void -__gnat_gmem_read_bt_frame (buf) - char *buf; +void __gnat_gmem_symbolic (void * addr, char* buf, int* length) { - int l = 0; - char s[1000]; - char *name, *file; - - if (cur_tb_pos >= cur_tb_len) - { - buf[0] = ' '; - buf[1] = '\0'; - return; - } - - convert_addresses (tracebk + cur_tb_pos, 1, s, &l); - s[l] = '\0'; - name = spc2nul (s) + 4; - file = spc2nul (name) + 4; - spc2nul (file); - ++cur_tb_pos; + char* addresses [] = { (char*)addr }; + extern char** gnat_argv; - sprintf (buf, "# %s () at %s", name, file); + convert_addresses (addresses, 1, buf, length); } |