24 #include <sys/types.h>
35 #ifdef DWDEBUG_MEMDEBUG
52 static GHashTable *debugfile_tab = NULL;
53 static GHashTable *debugfile_id_tab = NULL;
55 static int debugfile_id_idx = 0;
59 .srcfile_filter = NULL,
60 .symbol_filter = NULL,
64 static const char *DEBUGPATHS[] = {
66 "/usr/local/lib/debug",
70 static int init_done = 0;
73 static GMemVTable system_malloc_gmemvtable = {
87 #ifdef DWDEBUG_MEMDEBUG
88 if (getenv(
"G_SLICE") && strcmp(getenv(
"G_SLICE"),
"always-malloc") == 0)
89 g_mem_set_vtable(glib_mem_profiler_table);
95 debugfile_tab = g_hash_table_new_full(g_str_hash,g_str_equal,
97 debugfile_id_tab = g_hash_table_new_full(g_direct_hash,g_direct_equal,
108 g_hash_table_insert(debugfile_tab,debugfile->
filename,debugfile);
109 g_hash_table_insert(debugfile_id_tab,
110 (gpointer)(uintptr_t)debugfile->
id,debugfile);
111 RHOLD(debugfile,debugfile_tab);
118 if (debugfile_id_tab) {
119 if (g_hash_table_lookup(debugfile_id_tab,
120 (gpointer)(uintptr_t)debugfile->
id)
122 g_hash_table_remove(debugfile_id_tab,
123 (gpointer)(uintptr_t)debugfile->
id);
124 g_hash_table_remove(debugfile_tab,debugfile->
filename);
125 RPUT(debugfile,debugfile,debugfile_id_tab,trefcnt);
132 struct debugfile *debugfile;
134 if (debugfile_id_tab) {
135 list = g_hash_table_get_values(debugfile_id_tab);
145 struct debugfile *df;
154 while (g_hash_table_size(debugfile_tab) > 0) {
155 g_hash_table_iter_init(&iter,debugfile_tab);
156 while (g_hash_table_iter_next(&iter,NULL,(gpointer)&df)) {
161 g_hash_table_destroy(debugfile_tab);
162 debugfile_tab = NULL;
163 g_hash_table_destroy(debugfile_id_tab);
164 debugfile_id_tab = NULL;
196 const char *name,
const char *delim) {
200 char *saveptr = NULL;
207 verror(
"symbol %s is not a container!\n",
214 lname = strdup(name);
215 chain = array_list_create(0);
222 "starting at top-level %s: checking members\n",
228 while ((next = strtok_r(!saveptr ? lname : NULL,delim,&saveptr))) {
231 else if (anonchain && array_list_len(anonchain)) {
236 for (i = 0; i < array_list_len(anonchain); ++
i) {
238 (
struct symbol *)array_list_item(anonchain,i));
241 array_list_free(anonchain);
251 array_list_compact(chain);
265 const char *name,
const char *delim) {
270 RHOLD(lsymbol,lsymbol);
276 const char *name,
const char *delim) {
290 array_list_prepend_sublist(ls->
chain,lsymbol->
chain,-1);
293 for (i = 0; i < array_list_len(lsymbol->
chain) - 1; ++
i)
300 const char *name,
const char *delim) {
315 const char *name,
const char *delim) {
365 const char *name,
const char *delim) {
373 chain = array_list_clone(lsymbol->
chain,(newchild) ? 1 : 0);
388 char *filename,
int line) {
395 g_hash_table_iter_init(&iter,debugfile->
srclines);
396 while (g_hash_table_iter_next(&iter,&key,&value)) {
397 srcfile = (
char *)key;
401 if (strstr(srcfile,filename)) {
412 char *filename,
ADDR addr) {
421 while (g_hash_table_iter_next(&iter,&key,&value)) {
422 srcfile = (
char *)key;
424 if (filename && !strstr(srcfile,filename))
438 ADDR addr,
char **filename,
int *line) {
446 while (g_hash_table_iter_next(&iter,&key,&value)) {
453 *filename = (
char *)key;
464 char *filename,
int line,
475 for (i = 0; i < array_list_len(addrs); ++
i) {
476 iaddr = (
ADDR)array_list_item(addrs,i);
492 char *filename,
int line,
528 (scope->
range->
next != NULL) ?
";..." :
"",
548 (scope->
range->
next != NULL) ?
";..." :
"");
583 struct symbol *s = NULL,*
p = NULL,*a = NULL;
608 (scope->
range->
next != NULL) ?
";..." :
"",
628 (scope->
range->
next != NULL) ?
";..." :
"");
678 char *name,
const char *delim,
679 struct rfilter *srcfile_filter,
683 char *saveptr = NULL;
687 struct lsymbol *lsymbol_tmp = NULL;
690 struct scope *root_scope;
702 if (delim && strstr(name,delim)) {
703 lname = strdup(name);
704 next = strtok_r(!saveptr ? lname : NULL,delim,&saveptr);
705 chain = array_list_create(1);
715 && (symbol = g_hash_table_lookup(debugfile->
globals,next))) {
716 if (srcfile_filter) {
732 && (symbol = g_hash_table_lookup(debugfile->
types,next))) {
733 if (srcfile_filter) {
751 g_hash_table_iter_init(&iter,debugfile->
srcfiles);
752 while (g_hash_table_iter_next(&iter,&key,&value)) {
753 root = (
struct symbol *)value;
755 if (srcfile_filter) {
756 rfilter_check(srcfile_filter,key,&accept,&rfe);
767 lsymbol = lsymbol_tmp;
777 lsymbol = lsymbol_tmp;
785 lsymbol = lsymbol_tmp;
798 while (g_hash_table_iter_next(&iter,&key,&value)) {
800 if (srcfile_filter) {
801 rfilter_check(srcfile_filter,key,&accept,&rfe);
812 lsymbol = lsymbol_tmp;
822 lsymbol = lsymbol_tmp;
830 lsymbol = lsymbol_tmp;
846 if (srcfile_filter) {
847 rfilter_check(srcfile_filter,
852 "matched rf binfile srcfile %s; will check it\n",
857 "did not match rf binfile srcfile %s; not searching\n",
868 if (srcfile_filter) {
869 rfilter_check(srcfile_filter,
874 "matched rf binfile srcfile %s; will check it\n",
879 "did not match rf binfile srcfile %s; not searching\n",
976 "found top-level %s; checking members\n",lsymbol->
symbol->
name);
981 while ((next = strtok_r(!saveptr ? lname : NULL,delim,&saveptr))) {
986 else if (anonchain && array_list_len(anonchain)) {
991 for (i = 0; i < array_list_len(anonchain); ++
i) {
993 (
struct symbol *)array_list_item(anonchain,i));
996 array_list_free(anonchain);
1006 array_list_compact(chain);
1022 char *name,
const char *delim,
1023 struct rfilter *srcfile_filter,
1026 srcfile_filter,flags);
1029 RHOLD(lsymbol,lsymbol);
1035 struct rfilter *symbol_filter,
1037 struct rfilter *srcfile_filter) {
1038 GSList *retval = NULL;
1040 GHashTableIter iter;
1043 GHashTableIter iter2;
1045 struct symbol *
root;
1053 if (!symbol_filter) {
1061 g_hash_table_iter_init(&iter,debugfile->
types);
1062 while (g_hash_table_iter_next(&iter,&key,&value)) {
1064 symbol = (
struct symbol *)value;
1065 rfilter_check(symbol_filter,name,&accept,NULL);
1067 retval = g_slist_prepend(retval,symbol);
1070 while (g_hash_table_iter_next(&iter,&key,&value)) {
1072 symbol = (
struct symbol *)value;
1073 rfilter_check(symbol_filter,name,&accept,NULL);
1075 retval = g_slist_prepend(retval,symbol);
1079 g_hash_table_iter_init(&iter,debugfile->
globals);
1080 while (g_hash_table_iter_next(&iter,&key,&value)) {
1082 symbol = (
struct symbol *)value;
1084 rfilter_check(symbol_filter,name,&accept,NULL);
1086 retval = g_slist_prepend(retval,symbol);
1091 g_hash_table_iter_init(&iter2,debugfile->
srcfiles);
1092 while (g_hash_table_iter_next(&iter2,&key,&value)) {
1093 srcfile_name = (
char *)key;
1094 root = (
struct symbol *)value;
1096 if (srcfile_filter) {
1097 rfilter_check(srcfile_filter,srcfile_name,&accept,NULL);
1106 retval = g_slist_concat(retval,retlist);
1110 while (g_hash_table_iter_next(&iter2,&key,&value)) {
1111 srcfile_name = (
char *)key;
1113 if (srcfile_filter) {
1114 rfilter_check(srcfile_filter,srcfile_name,&accept,NULL);
1124 retval = g_slist_concat(retval,retlist);
1149 char *token2 = NULL;
1156 while ((token2 = strtok_r((!token2)?flagstr:NULL,delim,&saveptr2))) {
1158 if (strcmp(token2,
"NONE") == 0 || strcmp(token2,
"*") == 0) {
1162 else if (strcmp(token2,
"CUHEADERS") == 0)
1164 else if (strcmp(token2,
"PUBNAMES") == 0)
1166 else if (strcmp(token2,
"NODWARF") == 0)
1168 else if (strcmp(token2,
"ALLRANGES") == 0)
1170 else if (strcmp(token2,
"KEEPDECLS") == 0)
1172 else if (strcmp(token2,
"PARTIALSYM") == 0)
1174 else if (strcmp(token2,
"REDUCETYPES") == 0)
1176 else if (strcmp(token2,
"REDUCETYPES_FULL_EQUIV") == 0)
1179 verror(
"unknown flag '%s'\n",token2);
1202 memset(opts,0,
sizeof(*opts));
1210 if (optstr && *optstr ==
'|' && *(optstr + 1) ==
'|')
1212 while ((token = strtok_r((!token)?optstr:NULL,
"||",&saveptr))) {
1218 verror(
"could not load flags!\n");
1223 rf = rfilter_create_parse(token);
1261 "debugfile opts %p matched '%s'\n",opts,name);
1262 if (match_saveptr) {
1263 *match_saveptr =
opts;
1269 "not using debugfile opts %p for '%s'\n",opts,name);
1302 struct debugfile *debugfile;
1305 verror(
"invalid dtype %d!\n",dtype);
1311 debugfile = (
struct debugfile *)
calloc(1,
sizeof(*debugfile));
1320 debugfile->
type = dtype;
1323 debugfile->
filename = strdup(filename);
1324 debugfile->
id = ++debugfile_id_idx;
1325 debugfile->
flags = dtflags;
1341 struct debugfile *debugfile;
1344 debugfile = (
struct debugfile *)
calloc(1,
sizeof(*debugfile));
1353 debugfile->
type = dtype;
1358 debugfile->
id = ++debugfile_id_idx;
1359 debugfile->
flags = dtflags;
1364 RHOLD(binfile,debugfile);
1367 if (binfile_pointing) {
1369 RHOLD(binfile_pointing,debugfile);
1377 if (!dtype && binfile) {
1383 debugfile->
ops = NULL;
1387 verror(
"no debugfile_type_t nor binfile!\n");
1407 debugfile->
srcfiles = g_hash_table_new_full(g_str_hash,g_str_equal,
1417 debugfile->
cuoffsets = g_hash_table_new(g_direct_hash,g_direct_equal);
1423 debugfile->
globals = g_hash_table_new(g_str_hash,g_str_equal);
1429 debugfile->
types = g_hash_table_new(g_str_hash,g_str_equal);
1431 debugfile->
shared_types = g_hash_table_new(g_str_hash,g_str_equal);
1433 debugfile->
decllists = g_hash_table_new_full(g_str_hash,g_str_equal,
1435 (GDestroyNotify)array_list_free);
1437 debugfile->
decldefnsused = g_hash_table_new(g_direct_hash,g_direct_equal);
1443 debugfile->
addresses = g_hash_table_new(g_direct_hash,g_direct_equal);
1449 debugfile->
pubnames = g_hash_table_new_full(g_str_hash,g_str_equal,
1457 debugfile->
srclines = g_hash_table_new_full(g_str_hash,g_str_equal,
1459 debugfile->
srcaddrlines = g_hash_table_new_full(g_str_hash,g_str_equal,
1463 debugfile->
ops->
init(debugfile);
1467 static int __realpath(
char *
filename,
char **realfilename) {
1470 rpname = realpath(filename,NULL);
1474 *realfilename =
calloc(strlen(rpname)+1,
sizeof(
char));
1475 sprintf(*realfilename,
"%s",rpname);
1481 static int _debugfile_filename_info(
char *filename,
char **realfilename,
1484 char *realname = NULL;
1486 if (__realpath(filename,&realname) == 0
1488 && strcmp(realname,filename) == 0) {
1490 realname = filename;
1492 else if (!realname) {
1493 verror(
"realpath(%s): %s\n",filename,strerror(errno));
1497 if (stat(realname,&sbuf) < 0) {
1498 verror(
"stat(%s): %s\n",realname,strerror(errno));
1499 if (realname != filename)
1505 *realfilename = realname;
1511 const char *DFPATH[],
char *buf,
int buflen) {
1512 char pbuf[PATH_MAX];
1517 debug_postfix =
".debug";
1519 DFPATH = DEBUGPATHS;
1521 for (i = 0; DFPATH[
i]; ++
i) {
1526 rc += snprintf(pbuf + rc,PATH_MAX - rc,
"%s",root_prefix);
1529 rc += snprintf(pbuf + rc,PATH_MAX - rc,
"/%s",DFPATH[i]);
1532 rc += snprintf(pbuf + rc,PATH_MAX - rc,
"/%s",filename);
1535 if (access(pbuf,R_OK) == 0)
1539 rc += snprintf(pbuf + rc,PATH_MAX - rc,
"%s",debug_postfix);
1540 if (access(pbuf,R_OK) == 0)
1546 "could not find '%s' (root_prefix='%s') in DFPATH!\n",
1547 filename,root_prefix);
1550 "could not find '%s' (root_prefix='%s') in DFPATH!\n",
1551 filename,root_prefix);
1558 strncpy(buf,pbuf,buflen);
1560 buf[buflen - 1] =
'\0';
1564 strncpy(buf,pbuf,rc + 1);
1585 struct array_list *debugfile_load_opts_list) {
1588 struct debugfile *debugfile = NULL;
1590 struct binfile *binfile_debuginfo = NULL;
1593 char pbuf[PATH_MAX];
1604 if (strstr(filename,root_prefix) != filename) {
1606 "BUG: filename '%s' does not start with root_prefix '%s';"
1608 filename,root_prefix);
1609 snprintf(pbuf,
sizeof(pbuf),
"%s%s",root_prefix,filename);
1610 filename = strdup(pbuf);
1615 if (_debugfile_filename_info(filename,&realname,&dtflags)) {
1617 "failed to get filename info for (%s): %s\n",
1618 filename,strerror(errno));
1621 if (debugfile_load_opts_list
1625 "opts prohibit loading of debugfile '%s'\n",realname);
1628 else if ((debugfile = (
struct debugfile *) \
1629 g_hash_table_lookup(debugfile_tab,realname))) {
1631 || (root_prefix != NULL
1660 if (!binfile_debuginfo) {
1661 if (errno != ENODATA) {
1662 verror(
"could not open debuginfo for binfile %s: %s!\n",
1663 binfile->
filename,strerror(errno));
1668 binfile_debuginfo = binfile;
1676 if ((debugfile = (
struct debugfile *) \
1677 g_hash_table_lookup(debugfile_tab,binfile_debuginfo->
filename))) {
1679 || (root_prefix != NULL
1684 RHOLD(debugfile,debugfile);
1699 binfile_debuginfo ? binfile_debuginfo : binfile,
1701 (binfile_debuginfo && binfile_debuginfo != binfile) \
1711 debugfile->
ops->
load(debugfile);
1713 dwdebug_save(debugfile);
1720 if (realname != filename)
1727 struct array_list *debugfile_load_opts_list) {
1731 struct debugfile *debugfile = NULL;
1733 struct binfile *binfile_debuginfo = NULL;
1737 if (_debugfile_filename_info(filename,&realname,&dtflags)) {
1739 "failed to get filename info for (%s): %s\n",
1740 filename,strerror(errno));
1743 if (debugfile_load_opts_list
1747 "opts prohibit loading of debugfile '%s'\n",realname);
1759 if (!binfile_debuginfo) {
1760 if (errno != ENODATA) {
1761 verror(
"could not open debuginfo for binfile %s: %s!\n",
1762 binfile->
filename,strerror(errno));
1767 binfile_debuginfo = binfile;
1778 binfile_debuginfo ? binfile_debuginfo : binfile,
1780 (binfile_debuginfo && binfile_debuginfo != binfile) \
1790 debugfile->
ops->
load(debugfile);
1799 if (realname != filename)
1806 struct array_list *debugfile_load_opts_list) {
1812 GHashTableIter iter;
1813 struct debugfile *df;
1815 if (!debugfile_tab || g_hash_table_size(debugfile_tab) == 0)
1818 retval = array_list_create(g_hash_table_size(debugfile_tab));
1819 g_hash_table_iter_init(&iter,debugfile_tab);
1820 while (g_hash_table_iter_next(&iter,NULL,(gpointer)&df))
1821 array_list_append(retval,df);
1827 struct symbol *tsymbol;
1835 else if (!symbol->
name) {
1844 if (array_list_find(symbol_list,symbol) >= 0) {
1846 "symbol at 0x%"PRIxSMOFFSET" already on the dup list!",
1850 array_list_append(symbol_list,symbol);
1853 " to existing duplist for srcfile name %s\n",
1857 else if ((tsymbol = g_hash_table_lookup(debugfile->
srcfiles,symbol->
name))
1858 && tsymbol != symbol) {
1868 symbol_list = array_list_create(0);
1869 array_list_append(symbol_list,tsymbol);
1871 strdup(tsymbol->
name),symbol_list);
1872 array_list_append(symbol_list,symbol);
1876 " to new duplist for srcfile name %s\n",
1879 else if (tsymbol == symbol)
1883 "adding top-level symbol %s:%s\n",
1885 g_hash_table_insert(debugfile->
srcfiles,symbol->
name,symbol);
1892 struct symbol *tsymbol;
1895 if ((tsymbol = (
struct symbol *) \
1896 g_hash_table_lookup(debugfile->
cuoffsets,
1897 (gpointer)(uintptr_t)symbol->
ref))
1898 && tsymbol != symbol) {
1900 " symbol(%s:0x%"PRIxSMOFFSET") already in debugfile %s!\n",
1905 else if (tsymbol == symbol)
1909 sr->debugfile = debugfile;
1911 g_hash_table_insert(debugfile->
cuoffsets,
1912 (gpointer)(uintptr_t)symbol->
ref,symbol);
1922 RHOLD(symbol,debugfile);
1934 struct symbol *tsymbol;
1937 if ((tsymbol = (
struct symbol *) \
1938 g_hash_table_lookup(debugfile->
cuoffsets,
1939 (gpointer)(uintptr_t)symbol->
ref))
1940 && tsymbol != symbol) {
1942 " symbol(%s:0x%"PRIxSMOFFSET") already in debugfile %s!\n",
1947 else if (tsymbol == symbol)
1948 g_hash_table_remove(debugfile->
cuoffsets,
1949 (gpointer)(uintptr_t)symbol->
ref);
1951 if ((tsymbol = g_hash_table_lookup(debugfile->
srcfiles,symbol->
name))
1952 && tsymbol != symbol) {
1954 " symbol(%s:0x%"PRIxSMOFFSET") already in debugfile %s!\n",
1959 else if (tsymbol == symbol)
1967 RPUT(symbol,symbol,debugfile,trefcnt);
1975 (gpointer)(uintptr_t)offset);
1983 symbol = (
struct symbol *)g_hash_table_lookup(debugfile->
srcfiles,name);
1989 return (
struct symbol *)array_list_item(alist,0);
1995 struct symbol *declaration,
1996 struct symbol *definition) {
2001 if (declaration->
type != definition->
type) {
2002 verror(
"declaration %s type %s (%p) != definition %s type %s (%p)!\n",
2043 if (g_hash_table_lookup_extended(debugfile->
decldefnsused,definition,
2044 NULL,NULL) == FALSE) {
2046 definition,definition);
2052 declaration->
addr = definition->
addr;
2056 memcpy(&declaration->
size,&definition->
size,
sizeof(definition->
size));
2093 decllist = array_list_create(1);
2094 g_hash_table_insert(debugfile->
decllists,
2095 strdup(symbol->
name),decllist);
2097 array_list_append(decllist,symbol);
2102 struct symbol *definition;
2111 definition = (
struct symbol *) \
2115 "globals lookup found definition '%s' type %s (%p)"
2116 " for declaration '%s' type %s (%p; trying to copy\n",
2125 "find_type found definition '%s' type %s (%p)"
2126 " for declaration '%s' type %s (%p; trying to copy\n",
2142 decllist = array_list_create(1);
2143 g_hash_table_insert(debugfile->
decllists,
2144 strdup(symbol->
name),decllist);
2146 array_list_append(decllist,symbol);
2150 static void __debugfile_resolve_decllist(
struct debugfile *debugfile,
2152 GHashTableIter *current_iter) {
2153 struct symbol *type_definition;
2154 struct symbol *instance_definition;
2155 struct symbol *definition;
2156 struct symbol *declaration;
2162 struct scope *declscope;
2165 instance_definition = (
struct symbol *) \
2166 g_hash_table_lookup(debugfile->
globals,name);
2168 if (!type_definition && !instance_definition) {
2170 "could not find any definitions for declarations named '%s'\n",
2175 total = array_list_len(decllist);
2176 copied = mapped = 0;
2179 definition = type_definition;
2181 definition = instance_definition;
2185 "could not find definition for declaration '%s'\n",
2195 "could not copy definition for declaration '%s'\n",
2229 "resolved %d (copied %d, mapped %d) of %d declarations named '%s'\n",
2230 copied+mapped,copied,mapped,total,name);
2232 if (array_list_len(decllist) == 0) {
2235 g_hash_table_iter_remove(current_iter);
2237 g_hash_table_remove(debugfile->
decllists,name);
2247 __debugfile_resolve_decllist(debugfile,name,decllist,NULL);
2251 GHashTableIter iter;
2255 g_hash_table_iter_init(&iter,debugfile->
decllists);
2256 while (g_hash_table_iter_next(&iter,
2257 (gpointer *)&name,(gpointer *)&decllist)) {
2258 __debugfile_resolve_decllist(debugfile,name,decllist,&iter);
2267 g_hash_table_insert(debugfile->
globals,symbol->
name,symbol);
2281 __debugfile_resolve_decllist(debugfile,symbol->
name,decllist,NULL);
2295 s = (
struct symbol *)g_hash_table_lookup(debugfile->
types,
typename);
2312 g_hash_table_insert(debugfile->
types,name,symbol);
2327 __debugfile_resolve_decllist(debugfile,symbol->
name,decllist,NULL);
2336 struct symbol *existing;
2347 existing = (
struct symbol *)g_hash_table_lookup(debugfile->
types,name);
2348 if (existing == symbol)
2351 RPUT(existing,symbol,debugfile->
types,trefcnt);
2353 g_hash_table_insert(debugfile->
types,name,symbol);
2369 __debugfile_resolve_decllist(debugfile,symbol->
name,decllist,NULL);
2385 int retval = debugfile->
refcnt;
2387 GHashTableIter iter;
2394 #ifdef DWDEBUG_MEMDEBUG
2416 snprintf(cmd,
sizeof(cmd),
"cat /proc/%d/status | grep Vm",getpid());
2428 verror(
"cannot free (%d refs) debugfile(%s)\n",
2430 return debugfile->
refcnt;
2433 vwarn(
"forced free (%d refs) debugfile(%s)\n",
2439 debugfile->
ops->
fini(debugfile);
2448 if (g_hash_table_lookup(debugfile_tab,debugfile->
filename) == debugfile)
2449 g_hash_table_remove(debugfile_tab,debugfile->
filename);
2450 if (g_hash_table_lookup(debugfile_id_tab,(gpointer)(uintptr_t)debugfile->
id)
2452 g_hash_table_remove(debugfile_id_tab,(gpointer)(uintptr_t)debugfile->
id);
2454 g_hash_table_destroy(debugfile->
pubnames);
2455 g_hash_table_destroy(debugfile->
addresses);
2456 g_hash_table_destroy(debugfile->
globals);
2457 g_hash_table_iter_init(&iter,debugfile->
types);
2458 while (g_hash_table_iter_next(&iter,NULL,(gpointer *)&symbol)) {
2459 RPUT(symbol,symbol,debugfile->
types,trefcnt);
2461 g_hash_table_destroy(debugfile->
types);
2462 g_hash_table_destroy(debugfile->
cuoffsets);
2468 g_hash_table_iter_init(&iter,debugfile->
srcfiles);
2469 while (g_hash_table_iter_next(&iter,NULL,(gpointer *)&symbol)) {
2473 RPUT(symbol,symbol,debugfile,trefcnt);
2474 g_hash_table_iter_remove(&iter);
2476 g_hash_table_destroy(debugfile->
srcfiles);
2478 while (g_hash_table_iter_next(&iter,NULL,(gpointer *)&symbol_list)) {
2483 RPUT(symbol,symbol,debugfile,trefcnt);
2485 array_list_free(symbol_list);
2486 g_hash_table_iter_remove(&iter);
2494 while (g_hash_table_iter_next(&iter,&kp,&vp)) {
2495 symbol = (
struct symbol *)vp;
2496 RPUT(symbol,symbol,debugfile,trefcnt);
2500 g_hash_table_destroy(debugfile->
decllists);
2507 while (g_hash_table_iter_next(&iter,&kp,NULL)) {
2508 symbol = (
struct symbol *)kp;
2511 " held by declaration symbols\n",
2514 g_hash_table_iter_remove(&iter);
2520 g_hash_table_destroy(debugfile->
srclines);
2555 symbol = (
struct symbol *)
malloc(
sizeof(*symbol));
2558 memset(symbol,0,
sizeof(*symbol));
2560 symbol->
type = symtype;
2588 struct symbol *origin;
2598 return symbol->
name;
2601 struct symbol *origin;
2616 if (!copy && symbol->
name && strcmp(symbol->
name,name) == 0)
2620 symbol->
name = strdup(name);
2635 insert_name =
malloc(strlen(symbol_name)+6);
2636 sprintf(insert_name,
"enum %s",symbol_name);
2640 insert_name =
malloc(strlen(symbol_name)+8);
2641 sprintf(insert_name,
"struct %s",symbol_name);
2645 insert_name =
malloc(strlen(symbol_name)+7);
2646 sprintf(insert_name,
"union %s",symbol_name);
2649 verror(
"cannot build extname for datatype %s!\n",
2654 verror(
"cannot build extname for type %s!\n",
2662 symbol->
name = insert_name;
2672 return symbol->
scope;
2694 " containing scope!\n",
2722 RHOLD(*scope,symbol);
2727 struct scope *new_parent) {
2741 if (scope && (symbol->
scope || new_parent) && !scope->
parent) {
2742 if (new_parent && new_parent != symbol->
scope)
2743 symbol->
scope = new_parent;
2764 verrorc(
" not a container; cannot insert child ");
2772 verrorc(
" not set to go on containing scope of parent enum type ");
2774 verrorc(
"; cannot insert!\n");
2782 verrorc(
" not set to go on owned scope of parent ");
2784 verrorc(
"; cannot insert!\n");
2795 RHOLD(child,parent);
2801 sc->members = g_slist_append(sc->members,child);
2802 RHOLD(child,parent);
2806 sf->members = g_slist_append(sf->members,child);
2807 RHOLD(child,parent);
2811 sb->members = g_slist_append(sb->members,child);
2812 RHOLD(child,parent);
2823 verrorc(
" does not have containing scope??\n");
2837 verrorc(
" does not have owned scope??\n");
2867 sc->members = g_slist_remove(sc->members,child);
2872 sf->members = g_slist_remove(sf->members,child);
2877 sb->members = g_slist_append(sb->members,child);
2885 struct symbol *newparent) {
2890 RHOLD(child,(
void *)0xdeadbeef);
2910 sc->members = g_slist_remove(sc->members,child);
2915 sf->members = g_slist_remove(sf->members,child);
2920 sb->members = g_slist_append(sb->members,child);
2931 RPUT(child,
symbol,(
void *)0xdeadbeef,trefcnt);
2946 return symbol->
name;
2963 return symbol->
type;
2971 struct symbol *origin;
2990 struct symbol *retval;
2991 struct symbol *origin;
3097 return symbol->
addr;
3109 scope = symbol->
scope;
3130 GSList *retval = NULL;
3139 retval = g_slist_append(retval,s);
3155 if (!scope || !scope->
symdict)
3162 struct symbol *
root;
3169 if (!sr || !sr->debugfile
3170 || !sr->debugfile->ops || !sr->debugfile->ops->symbol_root_expand) {
3174 return sr->debugfile->ops->symbol_root_expand(sr->debugfile,symbol);
3185 if (!sr || !sr->debugfile
3186 || !sr->debugfile->ops || !sr->debugfile->ops->symbol_expand) {
3191 return sr->debugfile->ops->symbol_expand(sr->debugfile,root,symbol);
3196 vwarn(
"symbol %s at srcline %d: line too large (max %d)!\n",
3222 vwarn(
"ctbytes %"PRIu32
" too big for field size!\n",b);
3236 vwarn(
"ctbytes %"PRIu32
" too big for field size!\n",tmpbytes);
3243 vwarn(
"bits %"PRIu32
" too big for field size!\n",b);
3249 uint32_t tmpbytes = (uint32_t)s->
size.
bytes;
3251 vwarn(
"ctbytes %"PRIu32
" too big for field size!\n",tmpbytes);
3258 vwarn(
"offset %"PRIu32
" too big for field size!\n",bo);
3264 vwarn(
"bits %"PRIu32
" too big for field size!\n",b);
3266 vwarn(
"offset %"PRIu32
" too big for field size!\n",bo);
3268 vwarn(
"ctbytes %"PRIu32
" too big for field size!\n",ctb);
3279 " lower than new addr 0x%"PRIxADDR"; not updating!\n",
3296 if (sr->compdirname && !sr->compdirname_nofree)
3297 free(sr->compdirname);
3298 if (compdirname && copy)
3299 sr->compdirname = strdup(compdirname);
3301 sr->compdirname = compdirname;
3302 sr->compdirname_nofree = !copy;
3308 if (sr->producer && !sr->producer_nofree)
3310 if (producer && copy)
3311 sr->producer = strdup(producer);
3313 sr->producer = producer;
3314 sr->producer_nofree = !copy;
3319 short int lang_code) {
3321 if (sr->language && !sr->language_nofree)
3323 if (language && copy)
3324 sr->language = strdup(language);
3326 sr->language = language;
3327 sr->language_nofree = !copy;
3328 sr->lang_code = lang_code;
3343 sf->entry_pc = entry_pc;
3344 sf->has_entry_pc = 1;
3348 sr->entry_pc = entry_pc;
3349 sr->has_entry_pc = 1;
3354 if (entry_pc < symbol->
addr) {
3355 symbol->
addr = entry_pc;
3370 "replacing existing location for symbol(%s:0x%"PRIxADDR")!\n",
3401 sii->origin_ref =
ref;
3402 sii->origin = origin;
3407 static int symbol_set_inline_instances(
struct symbol *
symbol,GSList *instances) {
3409 struct symbol *instance;
3413 RHOLD(instance,symbol);
3414 sii->inline_instances = g_slist_concat(sii->inline_instances,instances);
3423 sii->inline_instances = g_slist_append(sii->inline_instances,instance);
3424 RHOLD(instance,symbol);
3436 sv->constval = value;
3440 sv->constval =
malloc(len);
3441 memcpy(sv->constval,value,len);
3453 (gpointer)(uintptr_t)subrange);
3458 int symbol_change_scope(
struct symbol *symbol,
struct scope *
scope) {
3460 if (symbol->
scope == scope)
3466 symtab_steal_symbol(symbol->symtab,symbol);
3469 symbol->symtab = NULL;
3470 symtab_insert_symbol(symtab,symbol);
3488 symbol_change_symtab(tmpi->d.v.member_symbol,symtab);
3492 symbol_change_symtab(tmpi->d.v.member_symbol,symtab);
3499 if (SYMTAB_HAS_PARENT(symbol->s.ii->d.f.symtab))
3500 list_del(&symbol->s.ii->d.f.symtab->member);
3501 symbol->s.ii->d.f.symtab->hierarchy->parent = symtab;
3502 symtab->hierarchy->subtabs = g_slist_append(symtab->hierarchy->subtabs,
3503 symbol->s.ii->d.f.symtab);
3515 static inline int __check_type_in_list(
struct symbol *
type,
3520 if (array_list_find(list,type) > -1)
3526 static int __symbol_type_equiv(
struct symbol *t1,
struct symbol *t2,
3529 GHashTable *eqcache,
3530 GHashTable *updated_datatype_refs) {
3538 int rc1 = 0,rc2 = 0;
3541 GSList *gsltmp1,*gsltmp2;
3546 if (eqcache && g_hash_table_lookup(eqcache,t1) == t2)
3555 rc1 = __check_type_in_list(t1,*t1ss);
3557 rc2 = __check_type_in_list(t2,*t2ss);
3558 if ((rc1 || rc2) && rc1 == rc2) {
3562 else if (rc1 || rc2) {
3577 if ((!sn1 || !sn2) && sn1 != sn2)
3579 else if (!((sn1 == NULL && sn2 == NULL)
3580 || strcmp(sn1,sn2) == 0))
3584 if (*(uint32_t *)&t1->
size != *(uint32_t *)&t2->
size
3590 goto datatype_check;
3606 if (gsltmp1 || gsltmp2)
3618 if (m1_mlist == NULL && m2_mlist == NULL)
3620 else if (!m1_mlist || !m2_mlist)
3634 *t1ss = array_list_create(4);
3638 *t2ss = array_list_create(4);
3641 array_list_append(*t1ss,t1);
3642 array_list_append(*t2ss,t2);
3646 while (m1_mlist && m2_mlist) {
3647 m1 = m1_mlist->data;
3648 m2 = m2_mlist->data;
3650 m1_mlist = m1_mlist->next;
3651 m2_mlist = m2_mlist->next;
3654 if ((m1 == NULL && m2 == NULL)
3658 else if ((m1 == NULL && m2 != NULL)
3659 || (m1 != NULL && m2 == NULL)
3670 if (updated_datatype_refs) {
3671 t1d = (
struct symbol *) \
3672 g_hash_table_lookup(updated_datatype_refs,
3676 t2d = (
struct symbol *) \
3677 g_hash_table_lookup(updated_datatype_refs,
3686 if ((rc1 = __symbol_type_equiv(t1d,t2d,t1ss,t2ss,eqcache,
3687 updated_datatype_refs))) {
3694 array_list_remove(*t1ss);
3695 array_list_remove(*t2ss);
3700 array_list_free(*t1ss);
3704 array_list_free(*t2ss);
3713 if (m1_mlist != NULL || m2_mlist != NULL)
3725 if (m1_mlist == NULL && m2_mlist == NULL)
3727 else if (!m1_mlist || !m2_mlist)
3730 while (m1_mlist && m2_mlist) {
3731 m1 = m1_mlist->data;
3732 m2 = m2_mlist->data;
3734 m1_mlist = m1_mlist->next;
3735 m2_mlist = m2_mlist->next;
3737 if ((m1 == NULL && m2 != NULL)
3738 || (m1 != NULL && m2 == NULL)
3747 if (!retval && (m1_mlist != NULL || m2_mlist != NULL))
3777 if (updated_datatype_refs) {
3778 t1d = (
struct symbol *)g_hash_table_lookup(updated_datatype_refs,
3782 t2d = (
struct symbol *)g_hash_table_lookup(updated_datatype_refs,
3789 retval = __symbol_type_equiv(t1d,t2d,t1ss,t2ss,eqcache,updated_datatype_refs);
3797 g_hash_table_insert(eqcache,t1,t2);
3802 GHashTable *eqcache,GHashTable *updated_datatype_refs) {
3810 retval = __symbol_type_equiv(t1,t2,&t1ss,&t2ss,eqcache,updated_datatype_refs);
3817 struct symbol *retval = NULL;
3818 struct symbol **anonstack = NULL;
3819 int *parentstack = NULL;
3820 struct symbol **tmpstack = NULL;
3821 int *tmpparentstack = NULL;
3828 struct symbol *
type;
3831 struct symbol *tsymbol;
3854 if (tsymbol != symbol) {
3879 symbol = lsymbol->
symbol;
3915 if (stacklen == stackalen) {
3917 tmpstack = (
struct symbol **) \
3918 realloc(anonstack,
sizeof(
struct symbol *)*stackalen);
3920 verror(
"realloc anonstack: %s\n",strerror(errno));
3923 anonstack = tmpstack;
3925 tmpparentstack = (
int *) \
3926 realloc(parentstack,
sizeof(
int)*stackalen);
3927 if (!tmpparentstack) {
3928 verror(
"realloc parentstack: %s\n",
3932 parentstack = tmpparentstack;
3934 anonstack[stacklen] = retval;
3938 parentstack[stacklen] = i - 1;
3941 else if (retval->
name && strcmp(retval->
name,member) == 0) {
3948 stackalen,stacklen);
3951 stackalen,stacklen);
3953 if (i == stacklen) {
3975 symbol = lsymbol->
symbol;
4003 "returning result of searching S/U type symbol: ");
4037 if (chainptr && type != symbol) {
4046 for (j = i - 1; parentstack[j] != -1; j = parentstack[j])
4048 *chainptr = array_list_create(count);
4049 for (j = i - 1,k = count; k > 0; --k, j = parentstack[j]) {
4050 array_list_item_set(*chainptr,k-1,anonstack[j]);
4064 struct scope *scope;
4131 RHOLD(retval,retval);
4137 const char *delim) {
4138 char *saveptr = NULL;
4139 struct symbol *retval = NULL;
4141 char *mlist = strdup(memberlist);
4148 while ((member = strtok_r(!saveptr ? mlist : NULL,delim,&saveptr))) {
4157 RHOLD(retval,retval);
4163 struct symbol *origin;
4257 ((
int)(uintptr_t)elm) + 1);
4258 size = size * (((int)(uintptr_t)elm) + 1);
4279 int symbol_get_location_offset(
struct symbol *symbol,
OFFSET *offset_saveptr) {
4294 int symbol_get_location_addr(
struct symbol *symbol,
ADDR *addr_saveptr) {
4299 addr = symbol->
addr;
4312 *addr_saveptr =
addr;
4333 RPUT(symbol,symbol,symbol,retval);
4342 RPUT(symbol,symbol,symbol,retval);
4358 struct symbol *iisymbol;
4369 if (sii->inline_instances) {
4371 RPUT(iisymbol,symbol,symbol,trefcnt);
4373 g_slist_free(sii->inline_instances);
4374 sii->inline_instances = NULL;
4412 if (sr->compdirname && !sr->compdirname_nofree)
4413 free(sr->compdirname);
4414 if (sr->producer && !sr->producer_nofree)
4416 if (sr->language && !sr->language_nofree)
4419 if (sr->scope->symbol == symbol)
4420 sr->scope->symbol = NULL;
4421 RPUT(sr->scope,scope,symbol,trefcnt);
4426 && sr->debugfile->ops
4427 && sr->debugfile->ops->symbol_root_priv_free)
4428 sr->debugfile->ops->symbol_root_priv_free(sr->debugfile,symbol);
4439 RPUT(m,symbol,symbol,trefcnt);
4441 g_slist_free(sf->members);
4444 if (sf->scope->symbol == symbol)
4445 sf->scope->symbol = NULL;
4446 RPUT(sf->scope,scope,symbol,trefcnt);
4474 RPUT(m,symbol,symbol,trefcnt);
4476 g_slist_free(sb->members);
4479 if (sb->scope->symbol == symbol)
4480 sb->scope->symbol = NULL;
4481 RPUT(sb->scope,scope,symbol,trefcnt);
4494 RPUT(m,symbol,symbol,trefcnt);
4503 RPUT(m,symbol,symbol,trefcnt);
4505 g_slist_free(sc->members);
4508 if (sc->scope->symbol == symbol)
4509 sc->scope->symbol = NULL;
4510 RPUT(sc->scope,scope,symbol,trefcnt);
4517 int retval = symbol->
refcnt;
4584 symbol->
name = NULL;
4599 memset(lsymbol,0,
sizeof(
struct lsymbol));
4611 if (!lsymbol->
chain)
4612 lsymbol->
chain = array_list_create(1);
4615 array_list_append(lsymbol->
chain,symbol);
4620 RHOLD(symbol,lsymbol);
4624 if (!lsymbol->
chain)
4625 lsymbol->
chain = array_list_create(1);
4627 array_list_prepend(lsymbol->
chain,symbol);
4629 RHOLD(symbol,lsymbol);
4633 struct symbol *member) {
4637 chain = array_list_clone(parent->
chain,1);
4638 array_list_append(chain,member);
4647 struct symbol *member) {
4652 RHOLD(retval,retval);
4660 struct symbol *s = symbol;
4661 struct symbol *parent;
4666 chain = array_list_create(1);
4727 RHOLD(retval,retval);
4743 int i = array_list_len(lsymbol->
chain) - 1;
4744 struct symbol *s = lsymbol->
symbol;
4746 for ( ; i >= 0; --
i) {
4747 s = (
struct symbol *)array_list_item(lsymbol->
chain,i);
4759 struct symbol *s = NULL;
4760 struct symbol *ps = NULL;
4767 chain = array_list_create(array_list_len(lsymbol->
chain) - 1);
4769 for (i = 0; i < array_list_len(lsymbol->
chain); ++
i) {
4770 s = (
struct symbol *)array_list_item(lsymbol->
chain,i);
4772 array_list_append(chain,s);
4779 array_list_free(chain);
4789 struct lsymbol *retval;
4793 RHOLD(retval,retval);
4800 for (i = 0; i < array_list_len(lsymbol->
chain); ++
i) {
4801 RHOLD((
struct symbol *)array_list_item(lsymbol->
chain,i),lsymbol);
4807 RPUT(lsymbol,lsymbol,lsymbol,refcnt);
4812 int retval = lsymbol->
refcnt;
4828 if (lsymbol->
chain) {
4829 for (i = 0; i < array_list_len(lsymbol->
chain); ++
i) {
4830 RPUT((
struct symbol *)array_list_item(lsymbol->
chain,i),symbol,
4833 array_list_free(lsymbol->
chain);
4835 else if (lsymbol->
symbol) {
4836 RPUT(lsymbol->
symbol,symbol,lsymbol,trefcnt);
4848 gpointer
value,gpointer userdata) {
4851 struct symbol *symbol;
4856 fprintf(ud->
stream,
"\n");
4861 gpointer
value,gpointer userdata) {
4864 fprintf(ud->
stream,
"\n");
4868 void g_hash_foreach_dump_duplist(gpointer key,gpointer
value,gpointer userdata) {
4871 char *name = (
char *)key;
4876 sprintf(udn.prefix,
"%s%s",ud->
prefix,
" ");
4878 udn.meta = ud->
meta;
4881 fprintf(ud->
stream,
"%sduplist(%s):\n",ud->
prefix,name);
4882 for (i = 0; i < array_list_len(duplist); ++
i) {
4883 symbol_dump((
struct symbol *)array_list_item(duplist,i),&udn);
4884 fprintf(ud->
stream,
"\n");
4886 fprintf(ud->
stream,
"\n");
4893 struct scope *scope = (
struct scope *)data;
4894 if (scope && scope->
symbol)
4901 struct symbol *symbol = (
struct symbol *)data;
4908 int types,
int globals,
int symtabs,
int elfsymtab,
4917 np1 =
malloc(strlen(p) + 1 + 2);
4918 np2 =
malloc(strlen(p) + 1 + 4);
4919 sprintf(np1,
"%s%s",p,
" ");
4920 sprintf(np2,
"%s%s",p,
" ");
4932 fprintf(ud->
stream,
"%s flags: 0x%x\n",p,
4934 fprintf(ud->
stream,
"%s refcnt: %d\n",p,debugfile->
refcnt);
4935 fprintf(ud->
stream,
"%s types: (%d)\n",p,g_hash_table_size(debugfile->
types));
4938 fprintf(ud->
stream,
"%s shared_types: (%d)\n",
4943 fprintf(ud->
stream,
"%s globals: (%d)\n",
4944 p,g_hash_table_size(debugfile->
globals));
4947 fprintf(ud->
stream,
"%s root srcfiles: (%d)\n",
4948 p,g_hash_table_size(debugfile->
srcfiles));
4952 if (g_hash_table_size(debugfile->
srcfiles))
4953 fprintf(ud->
stream,
"\n");
4955 fprintf(ud->
stream,
"%s multi-use srcfile symtabs: (%d)\n",
4961 fprintf(ud->
stream,
"\n");
4964 fprintf(ud->
stream,
"%s ranges:\n",p);
4974 "%s binfile root: (tab=%d,anon=%d,dup=%d,subscopes=%d)\n",
4978 fprintf(ud->
stream,
"\n");
4981 fprintf(ud->
stream,
"%s binfile root ranges:\n",p);
4988 "%s binfile root: (tab=%d,anon=%d,dup=%d)\n",
4996 "%s binfile_pointing root: (tab=%d,anon=%d,dup=%d,subscopes=%d)\n",
5000 fprintf(ud->
stream,
"\n");
5003 fprintf(ud->
stream,
"%s binfile_pointing root ranges:\n",p);
5010 "%s binfile_pointing root: (tab=%d,anon=%d,dup=%d)\n",
5024 fprintf(ud->
stream,
" (compdirname=%s,producer=%s,language=%s (%d))",
5025 sr->compdirname,sr->producer,sr->language,sr->lang_code);
5027 if (ud->
detail && sr->scope) {
5028 fprintf(ud->
stream,
" {\n");
5033 fprintf(ud->
stream,
" { }\n");
5042 struct scope *scope;
5061 struct symbol *iisymbol;
5091 fprintf(ud->
stream,
"INLINED_PARAM(");
5096 fprintf(ud->
stream,
"INLINED_ANON_PARAM()");
5099 fprintf(ud->
stream,
"INLINED_PARAM(<UNK>)");
5109 fprintf(ud->
stream,
"INLINED_INSTANCE(");
5114 fprintf(ud->
stream,
"INLINED_ANON_INSTANCE(%s)",
5118 fprintf(ud->
stream,
"INLINED_INSTANCE(%s)",
5122 else if (symbol->
name) {
5132 fprintf(ud->
stream,
":%hd(%hd)(ct %d B)",
5144 || symbol->
isinlined || (sii && sii->inline_instances))) {
5145 fprintf(ud->
stream,
" (");
5148 fputs(
"external,",ud->
stream);
5150 fputs(
"isdecl,",ud->
stream);
5152 fputs(
"decldefined,",ud->
stream);
5154 fputs(
"declinline,",ud->
stream);
5156 fputs(
"inlined,",ud->
stream);
5160 if (sii && sii->inline_instances) {
5161 fprintf(ud->
stream,
"inlineinstances=(");
5180 fprintf(ud->
stream,
" @@ ");
5186 fprintf(ud->
stream,
" @@ CONST(%d,",sz);
5187 for (i = 0; i < sz; ++
i)
5188 fprintf(ud->
stream,
"%02hhx",
5207 struct symbol *member;
5208 struct symbol *iisymbol;
5245 fprintf(ud->
stream,
"INLINED_FUNC(");
5250 fprintf(ud->
stream,
"INLINED_ANON_FUNC() (%s)",
5254 fprintf(ud->
stream,
"INLINED_FUNC(<UNK>)");
5260 fprintf(ud->
stream,
" (");
5266 fprintf(ud->
stream,
", ");
5271 fprintf(ud->
stream,
"...");
5279 fputs(
"external,",ud->
stream);
5281 fputs(
"prototyped,",ud->
stream);
5283 fputs(
"decl,",ud->
stream);
5285 fputs(
"decldefined,",ud->
stream);
5287 fputs(
"declinline,",ud->
stream);
5289 fputs(
"inlined,",ud->
stream);
5290 if (sf && sf->fbloc) {
5291 fputs(
"frame_base=",ud->
stream);
5298 if (sii && sii->inline_instances) {
5299 fputs(
"inlineinstances=(",ud->
stream);
5321 if (sf && sf->scope) {
5331 struct symbol *member;
5332 struct symbol *member_datatype;
5345 fprintf(ud->
stream,
"<UNK>");
5351 fprintf(ud->
stream,
"void");
5358 fprintf(ud->
stream,
"[%d]",((
int)(uintptr_t)elm) + 1);
5362 fprintf(ud->
stream,
"[<UNK>]");
5366 fprintf(ud->
stream,
"const ");
5370 fprintf(ud->
stream,
"volatile ");
5385 fprintf(ud->
stream,
"%s",ss);
5397 fprintf(ud->
stream,
" { ");
5403 fprintf(ud->
stream,
"; ");
5410 if (member_datatype == symbol) {
5413 else if (member_datatype
5415 && !member_datatype->
name) {
5419 fprintf(ud->
stream,
" @@ ");
5424 fprintf(ud->
stream,
" @@ CONST(%p)",
5432 fprintf(ud->
stream,
" }");
5437 fprintf(ud->
stream,
"enum");
5449 fprintf(ud->
stream,
" { ");
5455 fprintf(ud->
stream,
", ");
5459 fprintf(ud->
stream,
" }");
5511 fprintf(ud->
stream,
"()");
5516 fprintf(ud->
stream,
" (prototyped=%d,external=%d) ",
5528 fprintf(ud->
stream,
", ");
5533 fprintf(ud->
stream,
"...");
5542 fprintf(ud->
stream,
"typedef ");
5579 np =
malloc(strlen(p) + 1 + 2);
5580 sprintf(np,
"%s%s",p,
" ");
5591 fprintf(ud->
stream,
"%stype: ",p);
5595 fprintf(ud->
stream,
"%sroot: ",p);
5599 fprintf(ud->
stream,
"%svar: ",p);
5603 fprintf(ud->
stream,
"%sfunc: ",p);
5607 fprintf(ud->
stream,
"%slabel: ",p);
5611 fprintf(ud->
stream,
"%sblock: ",p);
5615 fprintf(ud->
stream,
"unknown symbol type %d!\n",symbol->
type);
5630 char *prefixbuf = NULL;
5634 if (lsymbol->
chain && array_list_len(lsymbol->
chain)) {
5635 prefixbuf =
malloc(strlen(ud->
prefix) + (array_list_len(lsymbol->
chain) + 1) * 2 + 1);
5636 sprintf(prefixbuf,
"%s ",ud->
prefix);
5637 len = strlen(prefixbuf);
5643 if (++i == array_list_len(lsymbol->
chain))
5645 fprintf(ud->
stream,
"\n");
5646 prefixbuf[len++] =
' ';
5647 prefixbuf[len++] =
' ';
5648 prefixbuf[
len] =
'\0';
5651 else if (lsymbol->
symbol) {
5653 sprintf(prefixbuf,
"%s ",ud->
prefix);
5671 default:
return NULL;
5680 default:
return NULL;
5702 default:
return NULL;
#define SYMBOL_IST_NAMESPACE(sym)
int symbol_contains_addr(struct symbol *symbol, ADDR obj_addr)
int debugfile_add_type(struct debugfile *debugfile, struct symbol *symbol)
int debugfile_insert_root(struct debugfile *debugfile, struct symbol *symbol)
char * SYMBOL_SOURCE(int n)
#define LOCATION_ADDR(loc)
char * symbol_get_name_inline(struct symbol *symbol)
int symbol_insert_symbol(struct symbol *parent, struct symbol *child)
int symbol_has_unspecified_parameters(struct symbol *symbol)
uint32_t symbol_get_bitoffset(struct symbol *symbol)
OFFSET symbol_offsetof(struct symbol *symbol, const char *name, const char *delim)
#define vwarnopt(level, area, flags, format,...)
#define SYMBOL_EXPAND_WARN(symbol)
struct symbol * symbol_find_parent(struct symbol *symbol)
#define LOCATION_IS_ADDR(loc)
OFFSET lsymbol_offsetof(struct lsymbol *lsymbol, const char *name, const char *delim)
#define SYMBOLX_SUBRANGES(sym)
struct lsymbol * debugfile_lookup_sym__int(struct debugfile *debugfile, char *name, const char *delim, struct rfilter *srcfile_filter, symbol_type_flag_t flags)
int debugfile_declaration_copy_definition(struct debugfile *debugfile, struct symbol *declaration, struct symbol *definition)
void symbol_free_inline(struct symbol *symbol)
struct lsymbol * lsymbol_lookup_sym__int(struct lsymbol *lsymbol, const char *name, const char *delim)
struct scope * symbol_write_owned_scope(struct symbol *symbol)
struct debugfile * debugfile_from_file(char *filename, char *root_prefix, struct array_list *debugfile_load_opts_list)
unsigned int decltypedefined
GHashTable * decldefnsused
struct symbol * debugfile_find_type(struct debugfile *debugfile, char *typename)
unsigned int orig_name_offset
int symbol_set_root_language(struct symbol *symbol, char *language, int copy, short int lang_code)
void symbol_set_bytesize(struct symbol *s, uint32_t b)
#define SYMBOL_IST_VOL(sym)
void symbol_set_bitoffset(struct symbol *s, uint32_t bo)
REFCNT lsymbol_release(struct lsymbol *lsymbol)
GSList * symbol_get_ordered_members(struct symbol *symbol, symbol_type_flag_t flags)
struct lsymbol * debugfile_lookup_addr__int(struct debugfile *debugfile, ADDR addr)
void debugfile_save_declaration(struct debugfile *debugfile, struct symbol *symbol)
#define SYMBOL_IS_ELF(sym)
struct lsymbol * lsymbol_lookup_sym(struct lsymbol *lsymbol, const char *name, const char *delim)
#define SYMBOL_RX_ROOT(sym, rvar)
int symbol_set_constval(struct symbol *symbol, void *value, int len, int copy)
struct array_list * debugfile_lookup_addrs_line(struct debugfile *debugfile, char *filename, int line)
void location_dump(struct location *location, struct dump_info *ud)
struct lsymbol * lsymbol_create_from_symbol(struct symbol *symbol)
void clrange_symbol_name_dumper(Word_t start, Word_t end, struct dump_info *ud, void *data)
#define SYMBOL_RX_FUNC(sym, rvar)
struct symbol * symbol_create(symbol_type_t symtype, symbol_source_t source, char *name, int name_copy, SMOFFSET offset, load_type_t loadtype, struct scope *scope)
struct scope * symbol_read_owned_scope(struct symbol *symbol)
struct symbol * symbol_get_one_member__int(struct symbol *symbol, char *member)
unsigned int guessed_size
#define SYMBOL_RX_VAR(sym, rvar)
struct lsymbol * lsymbol_create_from_symbol__int(struct symbol *symbol)
GHashTable * shared_types
struct symbol * lsymbol_get_noninline_parent_symbol(struct lsymbol *lsymbol)
#define SYMBOL_WX_VAR(sym, wvar, reterr)
static uint64_t unsigned int i
struct array_list * clmatch_find(clmatch_t *clf, Word_t index)
GHashTable * srcaddrlines
int scope_insert_symbol(struct scope *scope, struct symbol *symbol)
#define SYMBOLX_MEMBERS(sym)
GSList * symdict_match_syms(struct symdict *symdict, struct rfilter *symbol_filter, symbol_type_flag_t flags)
struct array_list __attribute__
int symbol_get_srcline(struct symbol *symbol)
struct symbol * symbol_find_root(struct symbol *symbol)
#define v_g_slist_foreach(gslhead, gslcur, elm)
#define v_g_list_foreach(glhead, glcur, elm)
struct debugfile_load_opts * opts
int debugfile_type_flags_t
unsigned int size_is_bytes
struct symbol * __symbol_get_one_member__int(struct symbol *symbol, char *member, struct array_list **chainptr)
#define SYMBOL_IST_ENUM(sym)
void debugfile_handle_declaration(struct debugfile *debugfile, struct symbol *symbol)
struct symbol_block * block
#define SYMBOL_IS_FULL(sym)
char * debugfile_search_path(char *filename, char *root_prefix, char *debug_postfix, const char *DFPATH[], char *buf, int buflen)
#define SYMBOL_IS_INSTANCE(sym)
int symbol_is_enumerator(struct symbol *symbol)
int mallopt(int param, int value)
REFCNT symbol_free(struct symbol *symbol, int force)
ADDR symbol_get_addr(struct symbol *symbol)
struct debugfile * debugfile_from_binfile(struct binfile *binfile, struct array_list *debugfile_load_opts_list)
uint32_t symbol_get_bytesize(struct symbol *symbol)
struct lsymbol * lsymbol_create_from_member__int(struct lsymbol *parent, struct symbol *member)
void symbol_set_srcline(struct symbol *s, int sl)
void symbol_type_dump(struct symbol *symbol, struct dump_info *ud)
int symbol_type_equal(struct symbol *t1, struct symbol *t2, GHashTable *eqcache, GHashTable *updated_datatype_refs)
char * debugfile_get_name(struct debugfile *debugfile)
int symbol_is_decldefined(struct symbol *symbol)
void dwdebug_evict(struct debugfile *debugfile)
int debugfile_update_root(struct debugfile *debugfile, struct symbol *symbol)
void debugfile_resolve_declarations(struct debugfile *debugfile)
int symbol_is_inlineinstance(struct symbol *symbol)
#define verror(format,...)
int symbol_is_parameter(struct symbol *symbol)
debugfile_load_flags_t flags
#define verrorc(format,...)
#define SYMBOL_IST_CONST(sym)
struct lsymbol * lsymbol_clone(struct lsymbol *lsymbol, struct symbol *newchild)
char * symbol_get_srcfile(struct symbol *symbol)
#define SYMBOLX_ROOT(sym)
struct symbol * symbol_get_datatype(struct symbol *symbol)
struct debugfile_ops dwarf_debugfile_ops
#define SYMBOL_IS_CONTAINER(sym)
#define SYMBOLX_VAR_LOC(sym)
#define SYMBOL_IST_UNION(sym)
#define SYMBOL_WX_BLOCK(sym, wvar, reterr)
#define SYMBOL_IS_OWN_DATATYPE(sym)
#define SYMBOL_RX_BLOCK(sym, rvar)
int symbol_is_inlined(struct symbol *symbol)
struct lsymbol * debugfile_lookup_addr(struct debugfile *debugfile, ADDR addr)
int symbol_set_root_compdir(struct symbol *symbol, char *compdirname, int copy)
struct lsymbol * symbol_lookup_sym(struct symbol *symbol, const char *name, const char *delim)
GSList * scope_match_syms(struct scope *scope, struct rfilter *symbol_filter, symbol_type_flag_t flags)
int symbol_is_member(struct symbol *symbol)
struct binfile * binfile_open_debuginfo__int(struct binfile *binfile, struct binfile_instance *bfinst, const char *DFPATH[])
#define vwarn(format,...)
void lsymbol_dump(struct lsymbol *lsymbol, struct dump_info *ud)
int symbol_type_is_char(struct symbol *type)
struct symbol_type_container * container
struct symbol * scope_get_sym(struct scope *scope, const char *name, symbol_type_flag_t flags)
#define LOCATION_IS_M_OFFSET(loc)
struct lsymbol * lsymbol_create_from_member(struct lsymbol *parent, struct symbol *member)
#define SYMBOL_IS_LABEL(sym)
void clrange_free(clrange_t clf)
#define LOCATION_OFFSET(loc)
int symbol_has_ext_name(struct symbol *symbol)
void g_hash_foreach_dump_symbol(gpointer key __attribute__((unused)), gpointer value, gpointer userdata)
unsigned int constval_nofree
int(* load)(struct debugfile *debugfile)
char * lsymbol_get_name(struct lsymbol *lsymbol)
int symbol_set_encoding(struct symbol *symbol, encoding_t num)
int symbol_is_declaration(struct symbol *symbol)
#define list_for_each_entry(pos, head, member)
#define array_list_foreach(alist, lpc, placeholder)
int symbol_has_addr(struct symbol *symbol)
char * symbol_get_name_orig(struct symbol *symbol)
unsigned int symbol_type_array_bytesize(struct symbol *type)
void clmatchone_free(clmatchone_t clf)
int(* fini)(struct debugfile *debugfile)
struct scope * symbol_containing_scope(struct symbol *symbol)
void clmatch_free(clmatch_t clf)
int symbol_set_location(struct symbol *symbol, struct location *loc)
#define SYMBOL_RX_INLINE(sym, rvar)
void location_free(struct location *location)
struct debugfile_ops * ops
datatype_code_t datatype_code
#define SYMBOL_WX_CONTAINER(sym, wvar, reterr)
REFCNT debugfile_free(struct debugfile *debugfile, int force)
struct binfile * binfile_open__int(char *filename, char *root_prefix, struct binfile_instance *bfinst)
#define SYMBOL_IST_BASE(sym)
int symbol_is_prototyped(struct symbol *symbol)
void symbol_var_dump(struct symbol *symbol, struct dump_info *ud)
struct symbol * symbol_get_datatype_real(struct symbol *symbol)
unsigned int isprototyped
int scope_hold_symbol(struct scope *scope, struct symbol *symbol)
#define SYMBOL_TYPE_FLAG_MATCHES(sym, flags)
int(* init)(struct debugfile *debugfile)
struct dt_argp_state opts
struct debugfile_load_opts * debugfile_load_opts_parse(char *optstr)
#define SYMBOL_RX_LABEL(sym, rvar)
#define SYMBOL_IST_ARRAY(sym)
int symbol_type_flags_match(struct symbol *symbol, symbol_type_flag_t flags)
symbol_type_t symbol_get_type(struct symbol *symbol)
struct symbol * lsymbol_get_symbol(struct lsymbol *lsymbol)
void symbol_set_bitsize(struct symbol *s, uint32_t b)
#define SYMBOLX_ENCODING_V(sym)
#define SYMBOL_IST_PTR(sym)
#define SYMBOL_IST_FUNC(sym)
#define SYMBOL_IS_BLOCK(sym)
int symbol_add_inline_instance(struct symbol *symbol, struct symbol *instance)
int symbol_is_external(struct symbol *symbol)
void symbol_dump(struct symbol *symbol, struct dump_info *ud)
#define DWDEBUG_DEF_DELIM
#define ERRORDUMPSYMBOL_NL(s)
void clrange_dump(clrange_t *clf, struct dump_info *ud, clrange_dumper_t dumper)
void clrange_scope_name_dumper(Word_t start, Word_t end, struct dump_info *ud, void *data)
#define SYMBOL_IST_STRUCT(sym)
int debugfile_add_global(struct debugfile *debugfile, struct symbol *symbol)
struct debugfile * debugfile_create_basic(debugfile_type_t dtype, debugfile_type_flags_t dtflags, char *filename, struct debugfile_load_opts *opts)
#define SYMBOL_IST_STUNC(sym)
void symbol_set_addr(struct symbol *s, ADDR a)
int scope_remove_symbol(struct scope *scope, struct symbol *symbol)
void symbol_label_dump(struct symbol *symbol, struct dump_info *ud)
#define SYMBOL_IST_STUN(sym)
unsigned int has_unspec_params
int symbol_set_root_producer(struct symbol *symbol, char *producer, int copy)
char * debugfile_get_version(struct debugfile *debugfile)
struct lsymbol * scope_lookup_sym__int(struct scope *scope, const char *name, const char *delim, symbol_type_flag_t flags)
#define SYMBOL_WX_INLINE(sym, wvar, reterr)
int symbol_set_inline_origin(struct symbol *symbol, SMOFFSET ref, struct symbol *origin)
REFCNT symbol_release(struct symbol *symbol)
void debugfile_init_internal(struct debugfile *debugfile)
#define vdebug(devel, areas, flags, format,...)
struct debugfile * debugfile_create(debugfile_type_t dtype, debugfile_type_flags_t dtflags, struct binfile *binfile, struct debugfile_load_opts *opts, struct binfile *binfile_pointing)
int debugfile_remove_root(struct debugfile *debugfile, struct symbol *symbol)
void * realloc(void *ptr, size_t size)
unsigned int isdeclaration
void symbol_block_dump(struct symbol *symbol, struct dump_info *ud)
struct lsymbol * debugfile_lookup_sym(struct debugfile *debugfile, char *name, const char *delim, struct rfilter *srcfile_filter, symbol_type_flag_t flags)
REFCNT lsymbol_free(struct lsymbol *lsymbol, int force)
int debugfile_load_opts_checklist(struct array_list *opts_list, char *name, struct debugfile_load_opts **match_saveptr)
unsigned int isdeclinline
struct symbol * symbol_type_skip_qualifiers(struct symbol *type)
void debugfile_resolve_one_declaration(struct debugfile *debugfile, char *name)
void lsymbol_prepend(struct lsymbol *lsymbol, struct symbol *symbol)
#define vdebugc(devel, areas, flags, format,...)
#define SYMBOL_IS_TYPE(sym)
#define SYMBOL_RX_CONTAINER(sym, rvar)
struct rfilter * debugfile_filter
#define SYMBOLX_SCOPE(sym)
struct debugfile * debugfile_from_instance(struct binfile_instance *bfinst, struct array_list *debugfile_load_opts_list)
void * calloc(size_t nmemb, size_t size)
GHashTable * srcfiles_multiuse
struct scope * symbol_link_owned_scope(struct symbol *symbol, struct scope *new_parent)
uint32_t symbol_get_bitsize(struct symbol *symbol)
struct lsymbol * debugfile_lookup_sym_line__int(struct debugfile *debugfile, char *filename, int line, SMOFFSET *offset, ADDR *addr)
struct symbol * debugfile_lookup_root_name(struct debugfile *debugfile, char *name)
#define SYMBOL_HAS_EXTRA(sym)
struct symbol * debugfile_lookup_root(struct debugfile *debugfile, SMOFFSET offset)
#define SYMBOL_WX_FUNC(sym, wvar, reterr)
unsigned int symbol_type_full_bytesize(struct symbol *type)
GSList * debugfile_match_syms(struct debugfile *debugfile, struct rfilter *symbol_filter, symbol_type_flag_t flags, struct rfilter *srcfile_filter)
struct symbol * symbol_get_sym(struct symbol *symbol, const char *name, symbol_type_flag_t flags)
symbol_source_t symbol_get_source(struct symbol *symbol)
struct symbol * symbol_type_skip_ptrs(struct symbol *type)
struct binfile * binfile_pointing
int scope_get_sizes(struct scope *scope, int *named, int *duplicated, int *anon, int *numscopes)
struct debugfile_load_opts default_debugfile_load_opts
int debugfile_lookup_line_addr(struct debugfile *debugfile, char *filename, ADDR addr)
void symbol_set_name(struct symbol *symbol, char *name, int copy)
struct lsymbol * lsymbol_create_noninline__int(struct lsymbol *lsymbol)
#define SYMBOLX_VAR_CONSTVAL(sym)
GSList * symbol_get_members(struct symbol *symbol, symbol_type_flag_t flags)
struct symbol * symbol_get_inline_origin(struct symbol *symbol)
struct lsymbol * lsymbol_create(struct symbol *symbol, struct array_list *chain)
struct scope * scope_lookup_addr(struct scope *scope, ADDR pc)
struct array_list * debugfile_get_loaded_debugfiles(void)
struct rfilter * srcfile_filter
int symbol_set_root_priv(struct symbol *symbol, void *priv)
struct rfilter * symbol_filter
int scope_insert_scope(struct scope *parent, struct scope *child)
int symbol_change_parent(struct symbol *parent, struct symbol *child, struct symbol *newparent)
int symbol_expand(struct symbol *symbol)
struct symbol * symbol_get_member(struct symbol *symbol, char *memberlist, const char *delim)
int debugfile_lookup_filename_line_addr(struct debugfile *debugfile, ADDR addr, char **filename, int *line)
#define array_list_foreach_continue(alist, lpc, placeholder)
#define SYMBOL_IS_ROOT(sym)
void scope_dump(struct scope *scope, struct dump_info *ud)
char * SYMBOL_TYPE(int n)
int symbol_set_inline_info(struct symbol *symbol, int isinlined, int isdeclinline)
#define SYMBOL_IST_VOID(sym)
void g_hash_foreach_dump_symbol_list(gpointer key __attribute__((unused)), gpointer value, gpointer userdata)
void lsymbol_append(struct lsymbol *lsymbol, struct symbol *symbol)
#define array_list_foreach_delete(alist, lpc)
struct symbol_function * function
int symbol_is_synthetic(struct symbol *symbol)
debugfile_type_flags_t flags
char * symbol_get_name(struct symbol *symbol)
void dwdebug_evict_all(void)
#define RPUT(x, objtype, hx, rc)
void debugfile_load_opts_free(struct debugfile_load_opts *opts)
#define SYMBOL_IST_CONTAINER(sym)
struct symbol_root * root
#define SYMBOL_HAS_MEMBERS(sym)
void * malloc(size_t size)
void symbol_free_extra(struct symbol *symbol)
void symbol_build_extname(struct symbol *symbol)
#define ERRORDUMPSYMBOL(s)
void * clrange_find(clrange_t *clf, Word_t index)
int symbol_add_subrange(struct symbol *symbol, int subrange)
struct array_list * chain
int symbol_is_bitsize(struct symbol *symbol)
unsigned int isinlineinstance
int scope_contains_addr(struct scope *scope, ADDR addr)
#define v_g_slist_foreach_dual(gslhead1, gslhead2, gslcur1, gslcur2, elm1, elm2)
void debugfile_dump(struct debugfile *debugfile, struct dump_info *ud, int types, int globals, int symtabs, int elfsymtab, int doranges)
int(* symbol_replace)(struct debugfile *debugfile, struct symbol *old, struct symbol *new)
#define SIZE_CTBYTES_SIZE
void symbol_root_dump(struct symbol *symbol, struct dump_info *ud)
char * symbol_get_compdirname(struct symbol *symbol)
#define SYMBOL_WX_ROOT(sym, wvar, reterr)
#define ERRORDUMPLSYMBOL_NL(s)
void symbol_set_bitsize_all(struct symbol *s, uint32_t b, uint32_t bo, uint32_t ctb)
debugfile_load_flags_t debugfile_load_flags_parse(char *flagstr, char *delim)
struct lsymbol * debugfile_lookup_sym_line(struct debugfile *debugfile, char *filename, int line, SMOFFSET *offset, ADDR *addr)
struct lsymbol * symbol_lookup_sym__int(struct symbol *symbol, const char *name, const char *delim)
int symbol_set_entry_pc(struct symbol *symbol, ADDR entry_pc)
void symbol_function_dump(struct symbol *symbol, struct dump_info *ud)
int symbol_is_definition(struct symbol *symbol)
int vdebug_is_on(int level, log_areas_t areas, log_flags_t flags)
#define SYMBOL_IST_TYPEDEF(sym)
#define SYMBOL_IS_FUNC(sym)
uint32_t symbol_get_bitctbytes(struct symbol *symbol)
struct lsymbol * lsymbol_create_noninline(struct lsymbol *lsymbol)
int symbol_is_bytesize(struct symbol *symbol)
unsigned int usesshareddatatype
unsigned int size_is_bits
int debugfile_lookup_addr_alt__int(struct debugfile *debugfile, ADDR addr, struct lsymbol **primary, struct lsymbol **alt)
#define ERRORDUMPLSYMBOL(s)
struct symbol * symbol_get_one_member(struct symbol *symbol, char *member)
#define SYMBOL_IS_VAR(sym)
int symbol_is_declinline(struct symbol *symbol)
clrange_t clrange_create(void)
#define SYMBOL_IST_CLASS(sym)
void lsymbol_hold_int(struct lsymbol *lsymbol)
struct scope * scope_create(struct symbol *owner, SMOFFSET ref)
#define SYMBOLX_INLINE(sym)
int debugfile_replace_type(struct debugfile *debugfile, struct symbol *symbol)
int symbol_remove_symbol(struct symbol *parent, struct symbol *child)