Commit graph

303 commits

Author SHA1 Message Date
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
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
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
55e0804d1d Fix some null-terminated strings issues in the procfs parsing 2016-06-20 18:22:25 +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
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
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
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
Sven Steinbauer
547f8bbc5c Infer fixes Round 2 (#4993) 2016-05-24 22:22:15 +02:00
Oscar Salvador Vilardaga
876f3fd547 Initial coredump support for Linux-x86-64 (no threads yet)
* http://man7.org/linux/man-pages/man5/core.5.html
* Able to dump the header and the program headers
* Checks /proc/[pid]/coredump_filter to know which maps should be dumped
* Check for bit 6 to 0 (priv/share anon mappings, priv/share file-backed, elf hdr, priv/share huge pages)
* Missing: priv/share DAX pages
2016-05-21 12:27:13 +02:00
SkUaTeR
75ea9cea3c Fix w32 debugger 2016-05-11 13:09:40 +02:00
Riccardo Schirone
26fc8f92ef libr: remove some unused variables and functions 2016-04-27 12:59:45 +02:00
pancake
6dfb95e9c5 Drop some unsupported debug features for osx-ppc 2016-04-27 11:40:42 +02:00
pancake
d24bc909ec Update sdb for osx-ppc and other 0.10.2 updates 2016-04-27 00:25:28 +02:00
pancake
280abd4f77 ARM can't hwstep by default 2016-04-22 10:15:22 +02:00
Jeffrey Crowell
6115d68736 libr/debug/p/debug_native.c: fix possible overflow 2016-04-19 09:08:15 -04:00
Jeffrey Crowell
96686841de handle spaces in shared library paths
fixes #4623
2016-04-18 14:04:38 -04:00
pancake
34a7837079 Include r_lib from r_bp 2016-04-13 14:48:17 +02:00
Jeffrey Crowell
74b5edd984 fix register get in dbg on BSD s/pc/PC 2016-04-11 12:34:42 -04:00
pancake
fe02539afb Fix some warnings for debug.mach0 2016-04-08 01:09:56 +02:00
Daniel Domínguez
71beec242e Coredump generation for Mach0 binaries 2016-04-05 12:03:59 +02:00
pancake
846263a51b Implement ios9 pangu's tfp0 in the debugger 2016-03-14 23:24:49 +01:00
pancake
f7fbbc419e Add dh in anal.x86-64.reg and fix some arm/x86 esil bugs 2016-02-22 01:14:06 +01:00
pancake
74b23f10b9 Merge branch 'xnu' of https://github.com/alvarofe/radare2 2016-02-06 22:37:52 +01:00
Álvaro Felipe Melchor
efa2a8ecdf xnu: step, breakpoint working with mach exception 2016-02-06 19:53:29 +01:00
Álvaro Felipe Melchor
feea7f4d17 xnu: change logic handle exception
instead of a thread waiting for incoming messages, i've implemented
wait functionality above mach_msg, now i have to make it work
with r2 and avoid while (1) in the code, understand better the
references and start thinking about edge cases
2016-02-02 20:27:57 +01:00
pancake
44a86928cc Fix some of the warnings in #4013 2016-01-27 03:14:19 +01:00
pancake
90e2fc3031 Fix reg-write in gdb-thumb and tiny io cache optimization 2016-01-27 00:26:49 +01: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
d9e77ca0d1 xnu: first series of patches to use mach exceptions
* use set_trace_bit and clear_trace_bit macros

* use PT_ATTACHEXC since PT_ATTACH will be deprecated in the future
and we are interested in receiving mach exceptions

* first attempt to handle mach exceptions

* api change: added a parameter to r_core_setup_debugger
at least in OS X this function was producing double attachment.
I've added a boolean value to indicate when use dpa.

* added pipe to communicate between main process and traced process
by far this is not a good implementation. We should develop a better
approach/design to save all the exceptions and handle them accordingly.
This is the initial implementation

* bring back ptrace for stability and in order to merge this into master
2016-01-18 22:24:16 +01:00
pancake
9051fed9e9 Fix #3951 - rarun2 with stdin and support for strings 2016-01-13 22:15:13 +01:00
pancake
40e08dbd89 Get rid of _Bool 2015-12-01 12:39:12 +01:00
pancake
2b51bf1acd Fix #3759 - ood on OSX 2015-11-25 11:52:29 +01:00