Commit graph

28 commits

Author SHA1 Message Date
pancake
dcc02e87c5 More if DEBUGGER for linux 2016-06-25 18:48:26 +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
16c27891a0 Switch to r_sys_perror for errors and fix two typos 2016-06-20 15:24:19 +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
8d9e4a7836 Fix double close in thread-list and non-null terminated string in debug.linux.core 2016-06-14 03:10:47 +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
pancake
48d5e668eb No more linux-ppc blindfixing. This one is for real 2016-05-19 16:21:57 +02:00
pancake
b3093c516c Blind fix the powerpc debugger build 2016-05-16 08:37:40 +02:00
pancake
b9eca47b02 Add regprofile for linux-powerpc (via @crowell) 2016-04-28 14:37:29 +02:00
pancake
d24bc909ec Update sdb for osx-ppc and other 0.10.2 updates 2016-04-27 00:25:28 +02:00
andrey.torsunov
169f3885c3 Fix checking /proc/%d/task for existence.
Since `/proc/%d/task` is directory, it make sense to use appropriate
check function. Therefore,`r_file_exists` function is not suitable
here, because it checks for existence of regular file.
2016-04-22 13:55:19 +02:00
Jeffrey Crowell
9a77bdc7d5 fix r_debug_reg_get to use PC instead of pc in dbg 2016-04-11 12:26:33 -04:00
pancake
8eabe785fe Boolify RDebug API 2015-12-04 02:57:56 +01:00
pancake
40ab1e2be6 Fix #3701 - Implement r_num_tail for dcu 2015-11-17 22:38:01 +01:00
pancake
1f56a8fad6 Finally working ARM64-linux (android) debugger 2015-11-17 16:06:45 +01:00
pancake
62a769fd49 Fix for linux/android-arm64 debugger 2015-11-13 00:26:40 +01:00
pancake
9c9bb2dbd5 Memory optimization for flags (-70%) + some warnfixes + sdb-sync 2015-11-08 23:38:42 +01:00
pancake
54e881daf8 Autoset Thumb in Debugger 2015-10-31 02:46:00 +01:00
pancake
2c86d90bd8 Implement dbt* and extend backtrace to support stack frame addresses 2015-10-22 12:38:57 +02:00
pancake
3de77ad6e6 Initial support of dbg.libs/unlibs for Linux/OSX 2015-10-22 04:48:56 +02:00
pancake
1d4b0d8555 Fix some covs 2015-08-28 17:21:04 +02:00
pancake
62755eeb0e Fix latest COVs 2015-08-25 12:40:21 +02:00
pancake
4dff5cca5e Some some COVs related to control flow and memory leaks 2015-08-24 01:58:36 +02:00
Álvaro Felipe Melchor
fb93dffde3 more cleanup in debug_native.c - linux 2015-08-19 17:31:00 +02:00
Álvaro Felipe Melchor
c959d92c9d WIP refactor debug 2015-08-11 08:53:05 +02:00