Commit Graph

844 Commits

Author SHA1 Message Date
pancake
dd6a168f82 Fix ood on OSX and clear raised on close 2016-06-26 04:51:44 +02:00
pancake
b53a99aca2 Mark some x86-specific code only for x86 2016-06-26 03:56:08 +02:00
pancake
dcc02e87c5 More if DEBUGGER for linux 2016-06-25 18:48:26 +02:00
pancake
4f785d398f Fix --disable-debugger on OSX 2016-06-25 04:26:07 +02:00
pancake
baca25dc73 Fix #5200 - __WALL is a linuxism, better use WAIT_ANY 2016-06-25 03:36:58 +02:00
Joshua J. Drake
99678d2fe0 Fix return consistency and clarify variable naming (#5199) 2016-06-23 10:40:14 +02:00
pancake
feff5b59e4 Do not use %p for ut64 values 2016-06-22 19:20:59 +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
pancake
bb00b4e91d Fix Android build, update Capstone and use Android's Studio NDK if available 2016-06-22 02:27:32 +02:00
pancake
136d1d722d Fix #5184 - Remove useless warning message in r_debug_set_arch 2016-06-20 23:42:56 +02:00
pancake
55e0804d1d Fix some null-terminated strings issues in the procfs parsing 2016-06-20 18:22:25 +02:00
Joshua J. Drake
16c27891a0 Switch to r_sys_perror for errors and fix two typos 2016-06-20 15:24:19 +02:00
Álvaro Felipe Melchor
564803d5c2 express db breakpoints as dbm due to ASLR 2016-06-19 14:04:23 +02:00
pancake
281d79da58 Remove some DEAD code and a copypaste error in coredump 2016-06-17 12:53:21 +02:00
pancake
f96f00d62d Fix #5158 - Merge r_db into r_util 2016-06-17 12:19:16 +02:00
Joshua J. Drake
0431a0efdf Properly handle forks on Linux 2.5.46+ (#5153)
Linux 2.5.46 made changes to the ptrace(2) API to inform a tracer when various
events occur. These are known as PTRACE_EVENTs. Start handling PTRACE_EVENTs
by:

 * Handling PTRACE_EVENT_FORK and PTRACE_EVENT_EXIT
 * For _FORK, stores the newly created pid in dbg->forked_pid
 * Add the "dpc" command to select the most recently forked child process.
 * Add the "dpc*" command to show the recently forked process' pid.

Additional minor changes to white space are included.

NOTE: This partially addresses #3549. It does handleLinux before 2.5.46.
2016-06-17 04:20:18 +02:00
Joshua J. Drake
9c21df9272 Minor cleanups to process handling (#5152)
* Fixed 'dpk' handling (signal wasn't being groked)
* Mostly comments added
* Some eprintfs added
2016-06-17 01:59:10 +02:00
pancake
66e783965f Fix build and oobreads in =!pid 2016-06-16 23:42:11 +02:00
Joshua J. Drake
e97e011426 Have r_debug_select change IO pids too (#5145) 2016-06-16 22:56:21 +02:00
Joshua J. Drake
fb820f9c8e Fixes #4875: Refactor process listing (#5144)
* Fixes #4875: Refactor process listing
* Move procfs-based process listing into linux_debug.c, guarded by __linux__
* Provide a warning and eprintf a TODO on the remaining platforms.
* Break reusable parts into linux_get_proc_pid and call it as needed.
* Add/remove comments for clarity
* Address feedback and re-enable non-Linux
2016-06-16 22:39:11 +02:00
Joshua J. Drake
285cd3b32f Minor tweaks to breakpoint handling
* Fix "dbm" help string
* Save <module>+<offset> as the name when using dbm
* Fix allocation patterns for "module"
* Remove commented out code
* White space fixes
2016-06-16 12:36:17 +02:00
pancake
e032a48cbe Fix latest 26 COVs 2016-06-14 23:47:58 +02:00
pancake
21a01d08fe Fix warnings in debug.linux.coredump 2016-06-10 04:20:28 +02:00
pancake
8d9e4a7836 Fix double close in thread-list and non-null terminated string in debug.linux.core 2016-06-14 03:10:47 +02:00
Jeffrey Crowell
3e8a0cc693 replace usage of killed r_str_trim 2016-06-10 01:12:07 +00:00
Jeffrey Crowell
ed47ce4fb3 add missing ; in debug_native.c 2016-06-09 21:16:02 +00:00
leberus
6b1a46be23 Add: Generate Coredump - added support for threads and x86 (#5104)
* Add: Generate Coredump - added support for threads and x86

* Fix: debug_native.c allow coredump for i386 too
2016-06-09 22:23:39 +02:00
Joshua J. Drake
a4b21680d8 Re-work r_debug_native_map_get to fix issues (#5108)
* Fixes #4972
* Check more return values
* Improve error reporting
* Minor formatting fixes
2016-06-09 22:12:16 +02:00
pancake
608b79d2b4 Finally fix the build on osx-ppc 2016-06-06 17:30:07 +02:00
pancake
4f51606b6d More osx-ppc build fixes.. 2016-06-06 16:55:15 +02:00
pancake
bd5e22c17e Some more osx-ppc fixes 2016-06-06 16:20:03 +02:00
oblique
f06e11b6f4 Fix warnings (#5078)
* Fix gcc warnings

* Fix strtoull return
2016-06-06 00:33:11 +02:00
Anton Kochkov
24c0dfc961 Do not include coredump.h for non x86 2016-06-02 08:07:12 +03:00
Anton Kochkov
c7f1f7a87b Add missing header for linux coredump 2016-06-02 07:55:31 +03:00
pancake
d3394d5a7a Fix latest 28 COVs 2016-06-02 03:19:31 +02:00
pancake
95b2e511f5 Fix some warnings 2016-06-01 12:23:10 +02:00
pancake
2d3a69b7a0 Fix linux-arm build 2016-05-26 12:29:24 +02:00
pancake
ba2011bdb9 Fix linux build on kernels < 3.2 2016-05-25 01:13:35 +02:00
Sven Steinbauer
547f8bbc5c Infer fixes Round 2 (#4993) 2016-05-24 22:22:15 +02:00
pancake
c36b299073 Fix some null deref and rarun2 chroot escape vuln 2016-05-24 12:32:45 +02:00
pancake
b28d5e0a9c Fix android build 2016-05-23 21:54:42 +02:00
Anton Kochkov
ab2db9544b Fix android build - never include <bits/uio.h> 2016-05-23 21:58:57 +03:00
pancake
6c35a016cf More fixes fore core-linux 2016-05-14 17:32:04 +02:00
Oscar Salvador Vilardaga
89218c49af Fix useless pnote pointer and small fix in linux-core-dump 2016-05-23 11:24:14 +02:00
pancake
2f908ce238 Fix 22 covs in linux-core-dump 2016-05-23 11:19:29 +02:00
pancake
4de93b2703 Fix coredump file generation 2016-05-21 15:11:16 +02:00
pancake
7ad752f038 Remove the sandbox and fix more bugs in linux-core 2016-05-21 14:40:09 +02:00
pancake
64201e9c34 Fix format string for the linux-core 2016-05-21 14:35:43 +02:00
pancake
987020ece3 Fix build and more cleanup for linux-coredump 2016-05-21 14:13:33 +02:00
pancake
98246ac212 Fix memleaks, syntax, author and other bugs in linux-coredump 2016-05-21 13:36:33 +02:00