Commit Graph

64 Commits

Author SHA1 Message Date
dromero
d250d21385 Fix for the #5671 issue (#5704) 2016-09-06 12:02:38 +02:00
Tiago Gasiba
f0a2d8657d Add support for conditional breakpoints running r2 commands 2016-09-01 19:11:46 +02:00
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
Á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
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
Álvaro Felipe Melchor
a93e75f542 Initial merge on the reworked patch from @alvarofe 2015-11-17 01:00:09 +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
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
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
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
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
pancake
887f15b03d Add r_bp_del_all (db-*) and fix some more bugs 2014-05-08 17:38:29 +02: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
pancake
1b2c8064ff * More split of core/cmd.c
* Fix 'dbc' argument parsing
* Fix V_q error message
* Remove unused code
2012-02-27 03:07:32 +01:00
pancake
4efc2bfab7 * rudi_s: Add r_list_foreach_safe() which is safe when deleting elements 2012-02-14 18:10:52 +01:00
pancake
ea98fe1bd6 * Various gcc-4.6 warnings fixed 2011-06-30 00:17:12 +02:00
pancake
07790d9932 * Check for null in r_bp_list printf
- Fixes segfault in Solaris
  - Close bug #5
2011-06-21 00:50:07 +02:00
Eloi Sanfelix
b4b909ec1a - Fixed breakpoint behaviour
* Find recoil
	* Set pc to addr-recoil properly
	* Fixed bp_restore: per bp, check if handled, else do via io.write

- Improved debug_gdb
	* Added 'read all regs to buffer'
	* Added breakpoint callback: check if supported first time, else return FALSE

- Maybe something else...
2011-05-11 20:08:19 +02:00
pancake
8924841072 * Some more work on r_core_sysenv*
- fix api, but still not using BLOCK or so
* Fix help for ??? and !?
* Upgrade swig/configure.acr to 0.6.9
2011-02-04 11:30:08 +01:00
pancake
773c2549ad * Initial implementation of callback commands for r_bp
- Added 'dbc' command to configure them
* Check breakpoint stop everywhere
2010-07-13 01:20:57 +02:00
pancake
bc2c79ee8d * Use RList in r_bp
- vapi updated
* Generalize the use of PrintfCallback typedef
  - used in r_bp and handled by r_cons in r_core
2010-06-30 01:13:09 +02:00
Nibble
4235dd2a8e * Fix bug with static plugins
* Treat r_cons and r_line as singleton in r_core_init
* Move gdiff to r_core
* Fix libgmp support

--HG--
rename : libr/diff/gdiff.c => libr/core/gdiff.c
rename : libr/diff/gdiff.h => libr/core/gdiff.h
2010-05-28 02:44:51 +02:00
Nibble
4ead120e53 * Rename "handler" to "plugin"
* Rename */handler.c to */plugin.c
* Rename "handle" to "handler" in r_lib

--HG--
rename : libr/bp/handle.c => libr/bp/plugin.c
rename : libr/cmd/handle.c => libr/cmd/plugin.c
rename : libr/debug/handle.c => libr/debug/plugin.c
rename : libr/io/handle.c => libr/io/plugin.c
2010-05-26 18:25:35 +02:00
Nibble
5c35f6e359 * Rename {r_*_handle_t, R*Handle} to {r_*_plugin_t, R*Plugin} 2010-05-26 01:42:22 +02:00
Nibble
7abcfe6852 * Refactoring
- Remove all init functions (included in _new)
  - Update vapi's (needs more work)
2010-05-20 17:40:58 +02:00
pancake
34435b1285 * Mental note: %lld/%llx does not exist on windows
- Use the macro PFMT64{xod} in case
2010-04-14 13:02:23 +02:00
Nibble
9af6794cec * Rename MALLOC_STRUCT into R_NEW and deprecate it. 2010-03-12 13:35:10 +01:00
pancake/fluendo
ef9224263a * Fix segfault in r_bp_get_bytes when used in loops
* Fix RRange vapi definition
* Remove dctl command. (dct with no argument)
* Add watch.o in bp/Makefile.. lacks implementation
2010-03-03 13:34:38 +01:00
pancake
08ffce4865 * Initial implementation of the r_bp_traptrace API
- Added endianness in r_bp
  - Add breakpoints for mips and ppc
  - Needs to be used from r_core (dbt?)
  - Added dummy bp_watch api (WIP: needs access to r_reg)
* Merge r_range inside r_util
* Added BIT_{SET|CHK} helpers in r_types_base
  - Define ST32_MAX

--HG--
rename : libr/range/range.c => libr/util/range.c
2010-03-03 02:41:41 +01:00
pancake
c50ea5b5a9 * Added support for LUA bindings
- Simple test program for r_bp
* Fix debugger build on arm/mips/powerpc
2010-03-03 00:13:22 +01:00