Skip to content

Commit

Permalink
Added support for including object handles in a2play export dumps
Browse files Browse the repository at this point in the history
Added -xh option, for dumping exports with (decimal integer) handles.

Closes #292.
  • Loading branch information
olofson committed Jan 4, 2017
1 parent c0cec78 commit 345bbeb
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions a2play/a2play.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ typedef enum {
DF_MODULE = 0x01, // Dump "work" module
DF_ROOT = 0x02, // Dump root (implies A2P_DF_MODULE)
DF_PRIVATE = 0x04, // Include private symbols
DF_ASM = 0x08 // Include VM asm code for programs
DF_ASM = 0x08, // Include VM asm code for programs
DF_HANDLES = 0x10 // Include object handles
} DUMPFLAGS;

static DUMPFLAGS dump = 0;
Expand Down Expand Up @@ -121,7 +122,7 @@ static void print_info(int indent, const char *xname, A2_handle h)
A2_otypes t = a2_TypeOf(iface, h);
const char *name = a2_Name(iface, h);
int has_exports = a2_GetExport(iface, h, 0) >= 1;
int has_private = (dump & DF_PRIVATE) &&
int show_private = (dump & DF_PRIVATE) &&
(a2_GetExport(iface, h, -1) >= 1);
char prefix[MAXINDENT * 2 + 1];
if(indent > MAXINDENT)
Expand All @@ -137,8 +138,12 @@ static void print_info(int indent, const char *xname, A2_handle h)
printf("%-24s", xname);
else if(name)
printf("%-24s", name);
else if(dump & DF_HANDLES)
printf("%-24s", "<unnamed>");
else
printf("%-24d", h);
if(dump & DF_HANDLES)
printf("%-8d", h);
printf("%-12s", a2_TypeName(iface, t));
switch(t)
{
Expand Down Expand Up @@ -243,23 +248,23 @@ static void print_info(int indent, const char *xname, A2_handle h)
printf("\n");
if((dump & DF_ASM) && (t == A2_TPROGRAM))
a2_DumpCode(iface, h, stdout, prefix);
if(has_exports || has_private)
if(has_exports || show_private)
{
fputs(prefix, stdout);
printf("|----------------(exports)-------------------\n");
for(i = 0; (x = a2_GetExport(iface, h, i)) >= 0; ++i)
print_info(indent + 1, a2_GetExportName(iface, h, i),
x);
}
if(has_private)
if(show_private)
{
fputs(prefix, stdout);
printf("|-------------(private symbols)--------------\n");
for(i = -1; (x = a2_GetExport(iface, h, i)) >= 0; --i)
print_info(indent + 1, a2_GetExportName(iface, h, i),
x);
}
if(has_exports || has_private)
if(has_exports || show_private)
{
fputs(prefix, stdout);
printf("'--------------------------------------------\n");
Expand Down Expand Up @@ -432,8 +437,9 @@ static void usage(const char *exename)
" -sl<n> Stop level (1.0 <==> clip)\n"
" -x Dump module exports\n"
" -xr Dump engine root exports\n"
" -xp Dump private symbols\n"
" -xa Dump VM assembly code\n"
" -xp Dump with private symbols\n"
" -xa Dump with VM assembly code\n"
" -xh Dump with object handles\n"
" -v Print engine and header "
"versions\n"
" -h Help\n\n");
Expand Down Expand Up @@ -522,6 +528,8 @@ static void parse_args(int argc, const char *argv[])
dump |= DF_MODULE | DF_PRIVATE;
else if(strncmp(argv[i], "-xa", 3) == 0)
dump |= DF_MODULE | DF_ASM;
else if(strncmp(argv[i], "-xh", 3) == 0)
dump |= DF_MODULE | DF_HANDLES;
else if(strncmp(argv[i], "-h", 3) == 0) /* No args! */
{
usage(argv[0]);
Expand Down

0 comments on commit 345bbeb

Please sign in to comment.