Commit Graph

107 Commits

Author SHA1 Message Date
Joshua J. Drake
722c62827b Major rework to the native debugger (esp on Linux) (#5185)
The major contribution here is completely re-worked breakpoint hit/recoil
handling. This work fixes #4907 and lays the ground work for future native
debugger improvements (multi-threading, etc).

* Give a human friendly type to enums
* Change many wait functions to return RDebugReasonType
* Better return checking (from r_debug_reg_sync, r_bp_restore)
* Optimized register synchronization
* Lots of comments and whitespace changes
* Improved inferior death detection

Handle EXIT_PID events differently than DEAD process events

* Move breakpoint/recoil handling to wait/cont/step

Rather than handing breakpoint related things inside cmd_debug.c, do that
inside the r_debug API functions. This seems like the most logical place for it
to live since it should apply to just about any platform/architecture.  This
also centralizes calling into "cmd.bp" handling via the CoreBind callback.

* Track how the caller wishes to continue

It turns out that handling break point recoils is very complicated. The ptrace
API on Linux returns SIGTRAP for just about every type of operation (not just
breakpoints getting hit). Add the "recoil_mode" flag to indicate whether we are
single-stepping or continuing and whether or not we are inside the recoil.

* Proper handling for swstep=true

Since r_debug_step_soft calls r_debug_continue, it's already hitting the recoil
case there. Move the recoil handling from r_debug_step to r_debug_step_hard
only.

For the swstep=true case, special handling is required inside r_debug_recoil.
By resetting all of the breakpoints except the one we just hit, we ensure we
can step the original instruction and hit the new swstep breakpoint. Add a new
bp function called r_bp_restore_except to do this.

To make matters worse, we cannot use a BreakpointItem pointer because that
leads to a use-after-free condition. Instead, we the breakpoint address
instead.

Now breakpoints should work regardless of the swtep setting.

* Always call the recoil before continuing

Some callers of r_debug_continue might not have ever inserted any breakpoints
before. If we don't restore breakpoints before each call to the underlying
continue we won't hit them.

* Hide software step breakpoint events from the user

When a breakpoint even happens due to a software-step, hide it from the user.
They aren't really breakpoints as far as they are concerned.

* Improve process exit handling on Linux

There are three types of process exiting events on Linux:

1. PTRACE_EVENT_EXIT occurs just before a process exits. It's not possible to
prevent it from exiting, but it can be used to inspect the pre-exit state.
2. The process can exit for a variety of reasons and we can notice when we call
waitpid(2).
3. The process could die randomly on us :-/

On Windows, h->wait will return R_DEBUG_REASON_EXIT_PID, but it's more likely
on Linux to find out the process is already dead.

* Check more bits within waitpid status

We can often make a decision about what happened strictly by looking at the
status returned from waitpid. In other cases, we need to call
r_debug_handle_signals.

If we reach the end of this function without knowing what happened, consider it
an error.
2016-06-22 10:34:45 +02:00
Joshua J. Drake
2b9edf8dc4 Fixes #5154: Stop including source-file whitespace (#5155) 2016-06-16 22:57:10 +02:00
Sven Steinbauer
8da8ad740f Cleanup fixes
* For commit comments and compiler errors
* Fixes for PR comments
* fix some "infer fixes" commits

Signed-off-by: Riccardo Schirone <sirmy15@gmail.com>
2016-05-23 11:25:44 +02:00
Álvaro Felipe Melchor
6b827c1563 Fix #4796 - Add dbm aka module relative breakpoints 2016-05-16 01:00:11 +02:00
pancake
80ea7427bb Indentation fixes around the previous commit and beyond 2016-05-15 10:40:57 +02:00
Joshua J. Drake
29c2670039 Fix #4560: Handle recoils well with swstep=true
When resuming after (during) recoil from a breakpoint, the swstep
implementation would fail to advance. In short, the debugger would immediately
interrupt again because r_bp_restore was re-setting the original breakpoint
just before continue. The following changes fix this issue:

1. Modify r_bp_get_in to stop including the byte after a breakpoint. This was
causing r_bp_recoil to fail because it thought there was already a breakpoint
on the next instruction.

2. Pass the real breakpoint address (pc - dbg->bpsize) to r_bp_recoil so
that r_bp_get_in can work properly. Stop adding the b->size there to keep it
going too.

3. Add a state flag to core->dbg to track that we are in the midst of a recoil.

4. When continuing from recoil (in r_debug_continue_kill), restore all
breakpoints except the one we just hit (with the new r_bp_restore_except) to
avoid hitting it again. Once we move past this instruction, that breakpoint
will be set again.
2016-05-15 10:19:24 +02:00
Damien Zammit
632dccc217 Remove LIL_ENDIAN macro and configure option
TODO: Remove other endian cruft from:
- hashing algs
- judy
- squashfs
- grub
- tms320

Signed-off-by: Damien Zammit <damien@zamaudio.com>
2016-05-06 10:21:55 +02:00
pancake
a74fd6c25f Use non-sigill breakpoints for ARM 2016-04-22 10:18:53 +02:00
NaveenBoggarapu
4c04b98b47 few memory leaks fixed 2016-04-13 21:55:48 +02:00
Anton Kochkov
878fa8d74c Fix breakpoints listing - missing space
My smallest commit ever.
2016-04-12 13:37:33 +04:00
Álvaro Felipe Melchor
c372743315 xnu: get rid of ptrace even for attach and detach
some rework in order to handle mach message as mach_exc_server and alike does
api change in plugin debug, now the function detach receive a pointer to RDebug
trying to deallocate port when are not needed any more
2016-01-23 22:50:28 +01:00
pancake
fc8ebbebc3 Fix breakpoints issue in ARM 2016-01-11 01:43:05 +01:00
Álvaro Felipe Melchor
e9a8431b7a Fix #3890 2015-12-29 22:35:37 +01:00
Álvaro Felipe Melchor
a93e75f542 Initial merge on the reworked patch from @alvarofe 2015-11-17 01:00:09 +01:00
pancake
e15c13322d Hack for arm64 breakpoints 2015-11-13 00:29:33 +01:00
pancake
36179944fd Fixes Thumb detection from CPSR, NULL 2015-10-31 03:45:14 +01:00
pancake
d651c626ed Fix breakpoints on Thumb/ARM debugger 2015-10-31 03:07:00 +01:00
pancake
a05ac7eaa4 RDebugPlugin.arch.typeof(char*) 2015-10-22 03:11:03 +02:00
pancake
9ec625269a Fix #2904 - Implement dbm and fix breakpoint list issue 2015-10-13 05:00:20 +02:00
XVilka
720341c2df Improve -fPIC handling, take 2 2015-10-09 22:24:15 +03:00
pancake
b86bf19c85 Fix #3051 - Honor CFLAGS everywhere and fix some windows/android warnings 2015-09-14 20:43:11 +02:00
pancake
49975ccf95 Fix #3286 - Use stdbool.h 2015-09-14 02:08:31 +02:00
Álvaro Felipe Melchor
1d4ebdeb25 some refactoring & added threads field in RDebug 2015-09-01 18:45:08 +02:00
dequis
003a18aa30 A few simple memory leak fixes 2015-08-30 23:20:51 +02:00
pancake
5993d290a0 Add dbn and db. commands 2015-08-17 01:43:45 +02:00
shuall
0807686d86 #3052 all printf member functions changed to cb_printf 2015-08-09 03:25:05 +02:00
pancake
fbdf0e8fde Fix some more COVs 2015-07-25 02:10:31 +02:00
Jonathan Neuschäfer
523aa3af5c add .version to all plugins 2015-07-12 19:05:33 +02:00
pancake
b5d40d11c0 Fix last coverities issues 2015-07-02 09:33:05 +02:00
Álvaro Felipe Melchor
daf8e5b06f Fix some infers 2015-06-28 20:15:35 +02:00
pancake
d436d16cd4 Honor asm.bits in the RBreakpoint API 2015-06-22 12:23:38 +02:00
pancake
20d6696d33 Workaround for arm breakpoints - wip and buggy 2015-06-01 16:18:29 +02:00
pancake
dc6aa4d796 Fix #2021 - Implement dbj and db* to list breakpoints in JSON 2015-02-01 02:53:18 +01:00
pancake
fb970bebb9 Honor LDFLAGS in more places (Thanks Gentoo guys for noticing)
https://bugs.gentoo.org/show_bug.cgi?id=391751
2015-01-27 17:46:56 +01:00
LemonBoy
832adcd557 Make the bp api slightly saner 2014-11-17 16:24:26 +01:00
pancake
211688f537 Handle bp.cmd and RBreakpointItem->cmd in RDebugContinue (bps and traces)
- Add scr.echo
2014-10-30 22:58:51 +01:00
skuater
c7e0681b38 add support for dbe* / dbd* / dbte* / dbtd* 2014-10-28 17:07:48 +01:00
pancake
ef35aaaa7e Add support for indexed breakpoint management 2014-10-28 11:14:30 +01:00
pancake
5248369cc0 Minor r_bp cleanup 2014-10-28 09:59:36 +01:00
pancake
8430ff1dba r_bp_get -> r_bp_get_at // .. r_bp_get_in 2014-10-28 02:28:58 +01:00
jvoisin
a60d82b800 Fix a lot of warnings for GCC
Less than 20 warnings remaining on my x86_64 GCC 4.9.1
2014-10-26 13:50:58 +01:00
pancake
1d3429db37 Update breakpoint counter for ARM 2014-10-10 22:45:03 +02:00
pancake
a0e609e40d Fix ARM swstepping and breakpoints, add dbg.bpsize 2014-09-26 13:57:03 +02:00
pancake
240e0d98a9 Fix some warnings 2014-09-20 10:13:48 +02:00
LemonBoy
76fa1fac1c Reap the breakpoint list correctly 2014-09-17 17:57:27 +02:00
LemonBoy
707089c3a9 Fix various debugger operations. Fix a ptrace-related bug. 2014-09-17 17:57:08 +02:00
pancake
887f15b03d Add r_bp_del_all (db-*) and fix some more bugs 2014-05-08 17:38:29 +02:00
pancake
dba63fbd3c Add some Jam files and merge rsign into ranal 2013-12-31 05:30:39 +01:00
pancake
d6de30eba4 More R_LIB_VERSION and initial r_asm_set_cpu() dummy api 2013-06-15 02:56:25 +02:00
pancake
fc9301b14b Add hints and named print formats and more
Initial implementation of anal hints (ah?)
Use anal hints in core/disasm. Needs more work
New data structure StrHT (string hashtable)
Simplify core/libs.c with cpp macros
Added r_cons_color() wip function for ansi256 consoles
RPrint no longer depends on r_cons
Sort 'a?' help commands
Add support for named print formats with pf$ command
Add support for 64 bit string pointers in 'pf' ('S')
Add r_print_mute and r_print_format_length functions
Bump r2 nodejs bindings version number
Merge r_print into r_util
2013-01-22 05:06:12 +01:00