-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add: dbg.libs/unlibs for linux #6567
Conversation
@@ -312,7 +312,13 @@ static bool setbpint(RCore *r, const char *mode, const char *sym) { | |||
if (bp) { | |||
bp->internal = true; | |||
#if __linux__ | |||
bp->data = r_str_newf ("?e %s: %s;dd", mode, sym); | |||
if (strncmp (sym, "sym.imp.dlclose", strlen ("sym.imp.dlclose"))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use r_str_startswith
if (strncmp (sym, "sym.imp.dlclose", strlen ("sym.imp.dlclose"))) { | ||
bp->data = r_str_newf ("?e %s: %s;ps@r:%s", mode, sym, | ||
!strncmp (sym, "sym.imp.dlmopen", strlen ("sym.imp.dlmopen")) | ||
? "rsi" : "rdi"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not portable. r2 have a way to determine the value of the register depending on the purpose, rsi/rdi is only for x86-64, and core/file.c is not the place to put arch-specific things
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you tell me more about this way? is a function?
dbg->reason.type = R_DEBUG_REASON_BREAKPOINT; | ||
dbg->reason.bp_addr = (ut64)siginfo.si_addr; | ||
{ | ||
#if 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the if 1
char no_str[128]; | ||
char mode[128] = {0}; | ||
|
||
sscanf (b->data, "%s %s %s", no_str, mode, no_str); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can overflow
char mode[128] = {0}; | ||
|
||
sscanf (b->data, "%s %s %s", no_str, mode, no_str); | ||
if (!strncmp (mode, "dbg.libs", strlen ("dbg.libs"))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use r_str_startswith
sscanf (b->data, "%s %s %s", no_str, mode, no_str); | ||
if (!strncmp (mode, "dbg.libs", strlen ("dbg.libs"))) { | ||
dbg->reason.type = R_DEBUG_REASON_NEW_LIB; | ||
} else if (!strncmp (mode, "dbg.unlibs", strlen ("dbg.unlibs"))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
} | ||
} | ||
#endif | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty line
rdi is the first argument, you can grab this name if you use the r_reg
R_API const char *r_reg_get_name(RReg *reg, int role) {
where role is R_REG_NAME_A0
this will return rdi for x86-64, but do the correct thing for x86-32, arm, ppc, ...
… On 24 Jan 2017, at 14:48, leberus ***@***.***> wrote:
@leberus commented on this pull request.
In libr/core/file.c <#6567>:
> @@ -312,7 +312,13 @@ static bool setbpint(RCore *r, const char *mode, const char *sym) {
if (bp) {
bp->internal = true;
#if __linux__
- bp->data = r_str_newf ("?e %s: %s;dd", mode, sym);
+ if (strncmp (sym, "sym.imp.dlclose", strlen ("sym.imp.dlclose"))) {
+ bp->data = r_str_newf ("?e %s: ***@***.***:%s", mode, sym,
+ !strncmp (sym, "sym.imp.dlmopen", strlen ("sym.imp.dlmopen"))
+ ? "rsi" : "rdi");
could you tell me more about this way? is a function?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#6567>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AA3-lptdUBWhBAB-1FhuMWdE2-E2J0Wvks5rVgFAgaJpZM4LsKac>.
|
well i guess i'll just put |
a064ab6
to
a7680fa
Compare
I've fixed all other issues. I'll do the reg's stuff now. |
if you rebase, travis should be green again :3 |
I've rebased, but I'm still testing this on i386/arm/arm64 |
travis doesnt tests the debugger, so that may not affect at all |
//dlmopen passes library's name in esi | ||
name = r_reg_get_name (dbg->reg, R_REG_NAME_A1); | ||
} | ||
snprintf (str, sizeof (str), ";ps@r:%s", name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use r_str_concatf ?
if (dbg->glob_libs || dbg->glob_unlibs) { | ||
ut64 pc_addr = r_debug_reg_get (dbg, "PC"); | ||
RBreakpointItem *b = r_bp_get_at (dbg->bp, pc_addr - dbg->bpsize); | ||
if (b) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use if (b && b->internal) and reduce 1 level of indentation
I've fixed the comments. |
Awesome! :D didnt expected to have all this stuff ready before the release! now let's focus on testing and finish the pending issues before release. to be sure we are not breaking anything Thanks! |
Yap! Actually I'm planning to start writing some tests for the debugger, so we realize faster if something gets fucked up by our changes :) |
This commits adds internal breakpoints for dlopen, dlmopen and dlclose.
A proper return reason has been added in linux_dbg_wait , so when typing
di
we can see the reason.Some things still have to be fixed:
bp->data
.First it prints the first part of the string (before ";"), and when it does a rcons_flush it prints everything (this issue was already here but i'll take a look).
struct library {
ut64 handler;
char *name;
};
The handler field would be the value returned from dlopen/dlmopen (value in rax). Once r2 detects a dbg.unlibs, it should compare all handlers we got so far with the one we're gonna close with dlclose (value passed in rdi).
And then we could keep this list in a lib field within RDebug structure.
So every time we unload a library, we can also print its name.