Commit Graph

625 Commits

Author SHA1 Message Date
pancake
b44ec9b3e3 Add =!pkt in gdb:// and other minor fixes 2016-09-14 13:11:04 +02:00
pancake
cadb0bd845 Several fixes for gdb:// on avr, still wip 2016-09-13 03:31:54 +02:00
pancake
a59e0ce083 Fix crash in gdb:// and some oobreads 2016-09-13 02:38:08 +02:00
leberus
03b2079c15 Fix: fix segfault for really long mapped files processes (#5714) 2016-09-09 14:30:41 +02:00
pancake
a458a36814 Fix android build 2016-09-07 00:10:25 +02:00
pancake
82d42ba5b2 Fix build and basic run of the ios-arm64 debugger 2016-08-31 02:30:20 +02:00
pancake
12a6469bbd Various fixes for the debug register state on XNU for ARM and x86 2016-08-31 01:57:36 +02:00
SkUaTeR
8b17834eb5 Fix command do in windows, fix dr command to get segments registers, … 2016-08-26 23:51:56 +02:00
leberus
74e6fda450 Coredump support for ARM and fix-ups (#5549)
* Fixes: 5540 (now i386 will not complain in case they're missing GETREGSET)
 * Fixup: Owner set to Linux for NT_PRXFPREG
 * Fixup: Now extra section hdr is being written with the right offset
 * Fixup: Bug with multithread cfg fixed
 * Add: Now r2 is able to generate coredumps on ARM platforms
2016-08-18 10:43:08 +02:00
pancake
123d1f1964 Fix android-x86 build 2016-08-16 19:27:55 +02:00
Eugene
b0970d563e fixes #5418 (#5421) 2016-07-30 18:56:24 +02:00
pancake
9b053064fd Fix dmp command for OSX and make it work with 1 parm instead of 3 2016-07-26 16:54:18 +02:00
pancake
2a2226978e Fix dmi on OSX and minor cydia tweak 2016-07-26 15:17:07 +02:00
pancake
30bdc476a1 Some cleanup in xnu.debug 2016-07-26 04:15:23 +02:00
Kamil Rytarowski
6ad9abb0b1 Fix NetBSD build in r_debug_native_pids() 2016-07-21 23:00:18 +02:00
Maijin
c274afe748 Fix #3286 - Use stdbool.h 2016-07-12 22:15:19 +02:00
leberus
8890d0650e Fix: segfault and #ifdef vs #if 2016-07-06 23:39:12 +02:00
skuater
39c4a0c35f some fix in windows debugger 2016-07-06 12:44:52 +03:00
nevun
d8d6d1a073 kvm_openfiles can fail so make sure we print the error message. (#5285)
* kvm_openfiles can fail so make sure we print the error message.

On OpenBSD you can use the kvm interface without /dev/kmem access but on FreeBSD
you need root or kmem access which one do not want to give a user.

Look at ps(1) on FreeBSD and see how they do it.
2016-07-05 04:13:10 +02:00
nevun
f41b706437 Fix OpenBSD build. Cannot do sizeof on a macro argument, compiler does not know what it is yet. (#5284) 2016-07-04 15:06:51 +02:00
nevun
5803182cbe Fixes issue #5279: kvm interface differs a bit between Open and FreeBSD. (#5282) 2016-07-04 14:32:11 +02:00
Eugene
3773a1d088 Added vars init in linux corefile gen (#5281) 2016-07-04 13:59:00 +02:00
pancake
df7c33f297 Fix build for Linux <= 2.6.32 (coredump not supported) 2016-07-04 01:45:44 +02:00
nevun
20801a3ee4 Make dm work on OpenBSD by adding a native r_debug_native_map_alloc() (#5267)
Note that OpenBSD can have mappings with zero size so relax the assert.

Also note that the protection bits are flipped. Different bit order. Will fix that later.
2016-07-02 13:22:28 +02:00
nevun
b5ec7a7145 Add support for dp and dp* on OpenBSD. (#5266)
* Add support for dp and dp* on OpenBSD.

kvm_getprocs exists on Net and Free as well so it might work there as well

* Cosmetic changes after feedback. Thanks.
2016-07-02 12:35:24 +02:00
Joshua J. Drake
09435c7317 Don't print SIGTRAP signals or stops
A TRAP signal signifes expected stops for breakpoints and so on. There's no
need to display these as signals or stops since they will be communicated
inside r_debug_bp_hit.
2016-07-01 21:32:02 -05:00
Pavel Borzenkov
fe9c419fa5 libr/debug: fix native debugger on Linux (#5259)
Linux kernel checks for unknown flags passed via the last argument to
waitpid() and fails waitpid() with EINVAL if it encounters one:

From kernel/exit.c:sys_wait4()

	if (options & ~(WNOHANG|WUNTRACED|WCONTINUED|
			__WNOTHREAD|__WCLONE|__WALL))
		return -EINVAL;

This makes it impossible to use debugger on Linux.

WAIT_ANY macro is actually supposed to be used as PID argument to wait
for all children without specifying particular PID.

Signed-off-by: Pavel Borzenkov <pavel.borzenkov@gmail.com>
2016-07-01 11:13:57 +02:00
Anton Kochkov
22e4a1d74c Fix Android build - 2nd try 2016-06-30 21:26:36 +03:00
Anton Kochkov
35f8178632 Fix Android build 2016-06-30 21:17:31 +03:00
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
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
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
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
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
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
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