Skip to content

Commit

Permalink
- Added next/n command in debugger so that the debug flow looks more …
Browse files Browse the repository at this point in the history
…like gdb

-> modified cont command to reflect this too

- Removed subtle bug in debug state machine that would not reinstall breakpoint if step was enabled in the middle
-> modularized code to be able to reuse e2dbg_breakpoint_reinstall()

- Added capability to foreach to record expression-typed values back in iterated list.

- Removed many gcc warnings
  • Loading branch information
may authored and may committed Mar 12, 2013
1 parent 4b1f955 commit 29735dd
Show file tree
Hide file tree
Showing 35 changed files with 575 additions and 403 deletions.
2 changes: 1 addition & 1 deletion evarista/callgraph-walk.esh
Expand Up @@ -11,7 +11,7 @@ print Entering FUNCTION: $func

#graph bloc $func.vaddr
cfg-walk $func.vaddr $2
#graph bloc $func.vaddr
graph bloc $func.vaddr

quiet

Expand Down
34 changes: 19 additions & 15 deletions evarista/sparc2lir.esh
Expand Up @@ -67,11 +67,11 @@ into Branch(addr:$curaddr, dst(val:$curaddr+$instr.op1.imm))

# indirect call (op1 reg)
case instr(sem:c, nb_op:1, op1(sem:reg))
into IndCallR(dst(rid:$instr.op1.baser))::Nop()
into IndCallR(dst(rid:$instr.op1.baser))::Nop(addr:$curaddr)

# direct call (op1 addr)
case instr(sem:c, nb_op:1, op1(sem:imm))
into Call(dst(val:$curaddr+($instr.op1.imm*4)))::Nop()
into Call(dst(val:$curaddr+($instr.op1.imm*4)))::Nop(addr:$curaddr)
#post profile disable warn

# ta* (traps)
Expand Down Expand Up @@ -181,20 +181,24 @@ default print Unsupported instruction at address $curaddr $instr

rwtend

lists transformed

##### fixme #####
# Add fields: XXX: fail if list size is more than 1 (field extension works well on 1 element)
#foreach $trans of $list[transformed]
# print $trans
# set $trans.szaffect $instrsz
# set $trans.addr $curaddr
# print $trans
#forend
#foreach $trans of $list[transformed]
# print $trans
#forend

#lists transformed

#exec sleep 3600
foreach $trans1 of $list[transformed]
print $trans1
set $trans1.szaffect $instrsz
set $trans1.addr $curaddr
print $trans1
forend

lists transformed

foreach $trans2 of $list[transformed]
print $trans2
forend

###########

add $curaddr 4

Expand Down
1 change: 1 addition & 0 deletions kedbg/register.c
Expand Up @@ -12,6 +12,7 @@ void kedbg_register_command(void)
revm_command_add(CMD_START, cmd_kedbgcont, NULL, 0, HLP_START);
revm_command_add(CMD_CONTINUE, cmd_kedbgcont, NULL, 0, HLP_CONTINUE);
revm_command_add(CMD_CONTINUE2, cmd_kedbgcont, NULL, 0, HLP_CONTINUE);
revm_command_add(CMD_CONTINUE3, cmd_kedbgcont, NULL, 0, HLP_CONTINUE);

/* Debugger only script commands */
revm_command_add(CMD_MODE, cmd_mode, revm_getvarparams, 0, HLP_MODE);
Expand Down
8 changes: 4 additions & 4 deletions libaspect/include/libaspect-profiler.h
Expand Up @@ -248,22 +248,22 @@ while(0)
#define INTERVAL(a, b, c) (a <= b && b < c)

/**
* Profiling macros
* Profiling macros - some artifact to shut gcc up
*/
#define NOPROFILER_IN() int profileme = 0
#define NOPROFILER_IN() int profileme = 0

#define NOPROFILER_OUT() \
do \
{ \
profileme = 0; \
if (profileme); \
return; \
} \
while (0)

#define NOPROFILER_ROUT(r) \
do \
{ \
profileme = 0; \
if (profileme); \
return (r); \
} \
while (0)
Expand Down
11 changes: 8 additions & 3 deletions libaspect/libhash.c
Expand Up @@ -185,8 +185,6 @@ int hash_add(hash_t *h, char *key, void *data)
u_int index;

PROFILER_IN(__FILE__, __FUNCTION__, __LINE__);

//Weaken the check : do not hash_get(h, key) check and do not check !data
if (!h || !key)
PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__,
"Invalid NULL parameters", -1);
Expand Down Expand Up @@ -233,6 +231,8 @@ int hash_del(hash_t *h, char *key)

PROFILER_IN(__FILE__, __FUNCTION__, __LINE__);

//fprintf(stderr, " DEL %s from %s \n", key, h->name);

/* Check the first entry for this hash */
actual = hash_get_head(h, key);
if (actual->key != NULL && !strcmp(actual->key, key))
Expand Down Expand Up @@ -318,9 +318,14 @@ int hash_set(hash_t *h, char *key, void *data)
{
listent_t *ent;

//fprintf(stderr, " SET %s in %s \n", key, h->name);

ent = hash_get_ent(h, key);
if (!ent || (!ent->key && !ent->data))
return (hash_add(h, key, data));
{
//fprintf(stderr, " NEWSET %s in %s \n", key, h->name);
return (hash_add(h, key, data));
}
ent->data = data;
return (0);
}
Expand Down
3 changes: 2 additions & 1 deletion libaspect/liblist.c
Expand Up @@ -465,7 +465,8 @@ char** elist_get_keys(list_t *h, int* n)
void elist_free_keys(char **keys)
{
PROFILER_IN(__FILE__, __FUNCTION__, __LINE__);
XFREE(__FILE__, __FUNCTION__, __LINE__, keys);
if (keys)
XFREE(__FILE__, __FUNCTION__, __LINE__, keys);
PROFILER_OUT(__FILE__, __FUNCTION__, __LINE__);
}

Expand Down
2 changes: 0 additions & 2 deletions libaspect/types.c
Expand Up @@ -317,7 +317,6 @@ aspectype_t *aspect_type_create(u_char isunion,
u_int idx;
u_int size;
hash_t fields_hash;
u_char updatetype;

PROFILER_IN(__FILE__, __FUNCTION__, __LINE__);

Expand All @@ -327,7 +326,6 @@ aspectype_t *aspect_type_create(u_char isunion,
"Invalid NULL parameter", NULL);

/* Subtyping was specified */
updatetype = 0;
supertype = NULL;
typename = strstr(label, "::");
if (typename)
Expand Down
4 changes: 2 additions & 2 deletions libaspect/vectors.c
Expand Up @@ -229,12 +229,12 @@ int aspect_register_vector(char *name,

if (!defaultfunc || !dimsz || !dimensions)
{
(void) write(1, "Invalid NULL parameters\n", 24);
write(1, "Invalid NULL parameters\n", 24);
return (-1);
}
if (vectype >= aspect_type_nbr)
{
(void) write(1, "Invalid vector element type\n", 28);
write(1, "Invalid vector element type\n", 28);
return (-1);
}

Expand Down
1 change: 1 addition & 0 deletions libe2dbg/include/libe2dbg.h
Expand Up @@ -571,6 +571,7 @@ int cmd_start();
int cmd_dumpregs();
int cmd_cont();
int cmd_threads();
int cmd_next();

/* Undefined on FreeBSD */
#if defined(__FreeBSD__)
Expand Down
9 changes: 9 additions & 0 deletions libe2dbg/user/continue.c
Expand Up @@ -69,6 +69,15 @@ int cmd_cont()
if (!world.state.revm_quiet)
e2dbg_output(" [*] Continuing process\n");

if (e2dbgworld.curthread->step)
{
if (e2dbg_resetstep() < 0)
PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__,
"Failed to disable stepping", -1);
e2dbgworld.curthread->step = 0;
e2dbgworld.curthread->count = E2DBG_BREAK_FINISHED;
}

/* Set back the current thread to the stopped thread */
e2dbg_setregs();
if (e2dbgworld.stoppedthread->tid != e2dbgworld.curthread->tid)
Expand Down
1 change: 1 addition & 0 deletions libe2dbg/user/dbg-ia32.c
Expand Up @@ -324,3 +324,4 @@ int e2dbg_break_ia32(elfshobj_t *f,
#endif
PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, (0));
}

5 changes: 4 additions & 1 deletion libe2dbg/user/e2dbg.c
Expand Up @@ -34,8 +34,11 @@ void e2dbg_register_command(void)
revm_command_add(CMD_DELETE , (void *) cmd_delete , revm_getvarparams, 1, HLP_DELETE);
revm_command_add(CMD_CONTINUE , (void *) cmd_cont , (void *) NULL, 1, HLP_CONTINUE);
revm_command_add(CMD_CONTINUE2, (void *) cmd_cont , (void *) NULL, 1, HLP_CONTINUE);
revm_command_add(CMD_CONTINUE3, (void *) cmd_cont , (void *) NULL, 1, HLP_CONTINUE);
revm_command_add(CMD_NEXT, (void *) cmd_next , (void *) NULL, 1, HLP_NEXT);
revm_command_add(CMD_NEXT2, (void *) cmd_next , (void *) NULL, 1, HLP_NEXT);
revm_command_add(CMD_START , (void *) cmd_start , (void *) NULL, 1, HLP_START);
revm_command_add(CMD_STEP , (void *) cmd_step , (void *) NULL, 1, HLP_STEP);
revm_command_add(CMD_STEP , (void *) cmd_next , (void *) NULL, 1, HLP_NEXT);
revm_command_add(CMD_DISPLAY , (void *) cmd_display , revm_getvarparams, 1, HLP_DISPLAY);
revm_command_add(CMD_UNDISPLAY, (void *) cmd_undisplay, revm_getvarparams, 1, HLP_UNDISPLAY);
revm_command_add(CMD_RSHT , (void *) cmd_rsht , revm_getregxoption, 1, HLP_RSHT);
Expand Down
70 changes: 32 additions & 38 deletions libe2dbg/user/resolv.c
Expand Up @@ -42,11 +42,6 @@ eresi_Addr e2dbg_dlsect(char *objname, char *sect2resolve,
u_int curoff;
eresi_Addr found_ref = 0;

#if __DEBUG_E2DBG__
char buf[BUFSIZ];
u_int len;
#endif

PROFILER_IN(__FILE__, __FUNCTION__, __LINE__);

#if __DEBUG_E2DBG__
Expand Down Expand Up @@ -128,7 +123,7 @@ eresi_Addr e2dbg_dlsect(char *objname, char *sect2resolve,

if (!obj.strsz)
{
write(2, " Unable to find STRSZ from PT_DYNAMIC\n", 39);
write(2, " Unable to find STRSZ from PT_DYNAMIC\n", 38);
return (-1);
}

Expand All @@ -139,14 +134,14 @@ eresi_Addr e2dbg_dlsect(char *objname, char *sect2resolve,
}

#if __DEBUG_E2DBG__
write(1, "6", 1);
write(2, "6", 1);
#endif

XSEEK(obj.fd, obj.stroff, SEEK_SET, 0);
XREAD(obj.fd, strtab, obj.strsz, 0);

#if __DEBUG_E2DBG__
write(1, "7", 1);
write(2, "7", 1);
#endif

/* XXX: Assume that strtab is always just after symtab */
Expand All @@ -167,24 +162,17 @@ eresi_Addr e2dbg_dlsect(char *objname, char *sect2resolve,
if (!found_ref)
{
//write(2, "Unable to find reference symbol in object\n", 42);
PROFILE_ERR(__FILE__, __FUNCTION__, __LINE__, "Unable to find reference symbol in object\n", 0);
PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, "Unable to find reference symbol in object\n", 0);
}


#if __DEBUG_E2DBG__
write(2, " Success !\n", 11);
//len = snprintf(buf, sizeof(buf),
// " [*] REFADDR = " XFMT " / FOUNDREF = " XFMT " / GOT = " XFMT " \n",
// refaddr, found_ref, got);
//write(2, buf, len);
#endif

/* Close the file */
XCLOSE(obj.fd, 0);

#if __DEBUG_E2DBG__
/* The reference addr is useful to deduce library base addresses */
write(2, "Now returning from e2dbg_dlsect \n", 33);

write(2, " [*] Succesfully resolved all needed symbols \n", 46);
#endif

return (got + refaddr - found_ref);
}

Expand All @@ -208,10 +196,12 @@ eresi_Addr e2dbg_dlsym(char *sym2resolve)
elfshlinkmap_t *curobj;
elfsh_Ehdr hdr;

/*
#if __DEBUG_E2DBG__
char buf[BUFSIZ];
u_int len;
#endif
*/

PROFILER_IN(__FILE__, __FUNCTION__, __LINE__);

Expand Down Expand Up @@ -286,12 +276,17 @@ eresi_Addr e2dbg_dlsym(char *sym2resolve)
return (-1);
}

#if __DEBUG_E2DBG__
/*
** You may not be able to call snprintf at this stage
** as some libc snprintf will call malloc (yuk).
**
#if __DEBUG_E2DBG__
len = snprintf(buf, sizeof(buf),
" [*] SYMOFF = "UFMT" ("XFMT"), STROFF = "UFMT" ("XFMT"), STRSZ = "UFMT" \n",
obj.symoff, obj.symoff, obj.stroff, obj.stroff, obj.strsz);
" [*] SYMOFF = "UFMT" ("XFMT"), STROFF = "UFMT" ("XFMT"), STRSZ = "UFMT" \n",
obj.symoff, obj.symoff, obj.stroff, obj.stroff, obj.strsz);
write(2, buf, len);
#endif
#endif
*/

XCLOSE(obj.fd, 0);

Expand All @@ -306,15 +301,20 @@ eresi_Addr e2dbg_dlsym(char *sym2resolve)
{
found_sym = cursym.st_value;

#if __DEBUG_E2DBG__
len = snprintf(buf, sizeof(buf),
" [*] FOUNDSYM (%s) = " XFMT "\n",
strtab + cursym.st_name, found_sym);
write(2, buf, len);
#endif
/*
** You may not be able to call snprintf on all OS
** as some implementations call malloc. Disabled
** formatted debugging.
#if __DEBUG_E2DBG__
len = snprintf(buf, sizeof(buf),
" [*] FOUNDSYM (%s) = " XFMT "\n",
strtab + cursym.st_name, found_sym);
write(2, buf, len);
#endif
*/

PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__,
curobj->laddr + found_sym);
curobj->laddr + found_sym);
}
}
}
Expand Down Expand Up @@ -344,7 +344,6 @@ elfshlinkmap_t* e2dbg_linkmap_getaddr()
Dl_info info;
#endif


#if __DEBUG_E2DBG__
char buf[BUFSIZ];
u_int len;
Expand Down Expand Up @@ -403,13 +402,8 @@ elfshlinkmap_t* e2dbg_linkmap_getaddr()
#endif

#if __DEBUG_E2DBG__
//len = sprintf(buf,
// " [*] Guessed Linkmap address = " XFMT " \n--------------\n",
// (eresi_Addr) lm);
//write(2, buf, len);
#endif

write(2, "Now returning from e2dbg_linkmap_getaddr \n", 42);
#endif

return (lm);
}
Expand Down

0 comments on commit 29735dd

Please sign in to comment.