Skip to content

Commit

Permalink
Fix empty struct and add test (#16408) ##types
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexis Ehret authored Apr 3, 2020
1 parent 8262fd4 commit 88d8357
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
10 changes: 5 additions & 5 deletions libr/core/cmd_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ static const char *help_msg_ts[] = {
"ts*", "", "Show pf.<name> format string for all loaded structs",
"ts*", " [type]", "Show pf.<name> format string for given struct",
"tsc", "<name>", "List all/given loaded structs in C output format with newlines",
"tsd", "", "List all loaded structs in C output format without newlines",
"tsd", "", "List all loaded structs in C output format without newlines",
"tss", " [type]", "Display size of struct",
"ts?", "", "show this help",
NULL
Expand Down Expand Up @@ -1040,7 +1040,7 @@ static int cmd_type(void *data, const char *input) {
break;
case 'd':
print_struct_union_in_c_format (TDB, stdifunion, r_str_trim_head_ro (input + 2), false);
break;
break;
case ' ':
showFormat (core, r_str_trim_head_ro (input + 1), 0);
break;
Expand Down Expand Up @@ -1394,9 +1394,9 @@ static int cmd_type(void *data, const char *input) {
RListIter *iter, *iter2;
RAnalFunction *fcn;
switch (input[1]) {
case '.': // "tx." type xrefs
case 'f': // "txf" type xrefs
fcn = r_anal_get_function_at (core->anal, core->offset);
case '.': // "tx." type xrefs
case 'f': // "txf" type xrefs
fcn = r_anal_get_function_at (core->anal, core->offset);
if (fcn) {
RList *uniq = r_anal_types_from_fcn (core->anal, fcn);
r_list_foreach (uniq , iter , type) {
Expand Down
6 changes: 4 additions & 2 deletions shlr/tcc/tccgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,10 @@ static void struct_decl(CType *type, int u) {
prevbt = VT_INT32;
bit_pos = 0;
offset = 0;

const char *ctype = (a == TOK_UNION)? "union": "struct";
tcc_appendf ("%s=%s\n", name, ctype);

while (tok != '}') {
if (!parse_btype (&btype, &ad)) {
expect ("bracket");
Expand Down Expand Up @@ -1172,10 +1176,8 @@ static void struct_decl(CType *type, int u) {
char *varstr = get_tok_str (v, NULL);
type_to_str (b, sizeof(b), &type1, NULL);
{
const char *ctype = (a == TOK_UNION)? "union": "struct";
int type_bt = type1.t & VT_BTYPE;
//eprintf("2: %s.%s = %s\n", ctype, name, varstr);
tcc_appendf ("%s=%s\n", name, ctype);
tcc_appendf ("[+]%s.%s=%s\n",
ctype, name, varstr);
tcc_appendf ("%s.%s.%s.meta=%d\n",
Expand Down
17 changes: 16 additions & 1 deletion test/new/db/cmd/types
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FILE=-
CMDS=<<EOF
e asm.arch=x86
e asm.bits=64
wx 41574156415541544989f4555389fd4881eca8030000488b3e64488b042528000000488984249803000031c0e82fb30000488d35d54e0100bf0600000
wx 41574156415541544989f4555389fd4881eca8030000488b3e64488b042528000000488984249803000031c0e82fb30000488d35d54e0100bf0600000
e asm.comments=false
s 2
tl short
Expand Down Expand Up @@ -1590,3 +1590,18 @@ EXPECT=<<EOF
c : 0x00000008 = (qword)0x8000000000000008
EOF
RUN

NAME=td empty struct
FILE=-
CMDS=<<EOF
wx 0xa00f
wx 0x401f @ 0x4
wx 0800000000000080 @ 0x8
"td struct foo {};"
tl foo @ 0x0
pd 1
EOF
EXPECT=<<EOF
(foo)
EOF
RUN

0 comments on commit 88d8357

Please sign in to comment.