Commit graph

61 commits

Author SHA1 Message Date
Khairul Azhar Kasmiran
2d49628aee
Remove rz_list_iter_get_data() (#5900)
* Remove rz_list_iter_get_data()
* Use rz_list_val() instead of rz_list_iter_get_data()
2026-02-10 22:03:37 +08:00
Khairul Azhar Kasmiran
b96202ad48
Rename rz_list_first() / rz_list_last() to rz_list_first_val() / rz_list_last_val() (#5654) 2025-12-20 17:08:59 +08:00
well-mannered-goat
7117ba75ea
librz/debug: add NetBSD debug tests and fix errors (#5208)
* Fix netbsd-x86_64 register profile
* Fix native_wait in netbsd.c
* Fix netbsd attach to show error
* Add netbsd-x64 debug tests
2025-06-20 00:22:33 +08:00
Giovanni
144b47d455
Move RzBreakpoint into RzDebug (#5124)
- Move trap/sw breakpoint into RzArch
- Remove RzBreakpointPlugin & RzBreakpointArch
- Add get_sw_breakpoint_at/get_sw_breakpoint_size_at binds
- Remove `dbh-`
- Change `dbh` to just list supported archs for sw breakpoints
- Implement correct PPC traps
- Add missing x86 breakpoint callback
2025-05-13 01:57:37 +08:00
Giovanni
e78a7be614
Remove dead code (#4705) 2024-11-08 18:46:13 +08:00
Rot127
30953d3bf6
refactor: Use HtSP for storing plugins. (#4687)
* Refactor: Use HtSP for storing plugins.

This saves iterations when searching for a plugin of a given name.
It also allows to save plugin configurations and data in hash table,
all addressed by their name. Hence, usage is more streamlined.

* Fix: iterators iterate over pointers of pointers.

* Soften the NULL check.

If arch is passed on from another struct, NULL is an allowed invalid value.

* Fix some leaks

* Fix NULL checks and incorrect inits

* Fix more leaks

* Add warning if plugin with same name was added before and is overwritten.

* Document rz_str_cmp

* Add function to create new list from iterator.

* Sort plugins alphabetically when listed.

* Fix parameter attributes, NULL checks, leaks and single rename.
2024-10-26 16:31:13 +08:00
Giovanni
db1e4993a0
Replace strdup with rz_str_dup (#4634) 2024-09-15 19:12:07 +08:00
pelijah
b8ebd5ac42
Add missing vector foreach macros to clang-format cfg (#4456)
* Add rz_vector_foreach to clang-format cfg
* Add other vector foreach macros
2024-04-22 07:16:46 +08:00
pelijah
f2d8e0db3d
Add HtSP, HtSS, HtSU, SetS (#4415)
- All `ht_*_new0()` are removed
- `freefn` field of HT options was renamed to `finiKV`
- `finiKV_user` fields was added to HT options
- Added `ht_*_new_opt_size` API
- `HtSP` and `HtUP` are created with `ValueFree` callback  that allows to reduce extra LOC and prevent bugs
- `SetP` replaced with `SetS` (based on `HtSP`)
- `rz_th_ht_*_new0()` and `rz_th_ht_*_new_opt()` are replaced with `rz_th_ht_*_new(HtXX *)`
2024-04-16 20:27:48 +08:00
z3phyr
de4a3c7419
Enhance dmht tcache command (#4355)
- Add tcache heap heuristics
- Fetch glibc version from libc
- Add unit testcases for glibc version

Co-authored-by: Giridhar Prasath R <giridh1337@gmail.com>
2024-03-22 11:00:58 +08:00
Giovanni
c17881ba2f
Initialize RzAnalysisOp properly. (#4350) 2024-03-10 18:26:10 +08:00
Huzaifa
58f7032f26
Add C API rz_debug_switch_to_first_thread() (#4287) 2024-02-26 21:13:33 +08:00
Anton Kochkov
85ffa899ec
Remove sdb_fmt() calls in RzDebug (#4135) 2024-01-21 23:24:52 +08:00
Florian Märkl
f3469946c5 Add specifiable size for watchpoints and tests
rz_bp_size_at() is not always the right size for a watchpoint, so we add
the possibility to specify the size as an extra argument to dmw.
2023-09-16 22:35:20 +08:00
Anton Kochkov
3278ec77d0
ci: use clang-format from LLVM 16 (#3696)
Co-authored-by: wargio <wargio@libero.it>
2023-08-01 09:11:26 +08:00
billow
6eb14128ad
Adding tricore support for rz_debug_plugin_gdb (#3557) 2023-06-06 12:53:51 +08:00
Riccardo Schirone
c4767cf1ac
Fix plugin removal and clean code (#3277)
* cmd: Fix summary of few "L" sub-commands
* util: start decluttering plugins handling

- Add Doxygen docs
- Remove unused API functions and make others internal only
- Use RzLibType enum for plugin type instead of int

* util: move dlopen/dlsym/dlclose to rz_sys
* util: make rz_lib_open/close return bool
* util: simplify rz_lib_add_handler and rz_lib_open*
* libs: implement rz_*_plugin_del to remove a plugin
* core: remove commands from RzCmd when removing plugins
* librz: call plugins 'fini' method when removing a plugin
* core/cmd: do not fail if the hashmap removal fails

When removing a group command, the inner command might have the same
name, thus it would result in trying to remove the same name twice.
Ignore it, as it is fine.

* librz: make RzCrypto plugins handling like the others
* librz/crypto: add rz_crypto_reset and use it
* librz: allocate the plugin structures before adding them
2023-01-16 13:32:46 +01:00
Florian Märkl
1b4385e224
Make xnu reg profile depend on cpu type instead of RzDebug.bits (#3270)
RzDebug.bits often has nonsensical contents set from all kinds of
places. Specifically, when debugging fat binaries on arm64, it had a
value not matching the debuggee when the reg profile was loaded,
resulting in the arm32 profile being used.
The right way to determine the profile is to do it after attach, when
the cpu type of the debuggee is known.
2023-01-07 17:43:41 +01:00
wargio
f137f983a7 Remove unimplemented methods in debug 2022-12-04 16:53:58 +01:00
wargio
18a4cb5582 Rewrite of bochs debugger and io plugin 2022-12-04 16:53:58 +01:00
wargio
47e674acb6 Adds sync_registers in debug plugin and cleanup brainfuck debugger 2022-12-04 16:53:58 +01:00
Dean
59b38e6efa
Add /*<type>*/ comments everywhere (#2986)
Adds /*<type>*/ comments and a linter check from rz-bindgen to enforce
their existence and consistency

Also includes the following fixes made when adding the annotations:
* removed unused intern_table arguments in pyc_dis.c, pyc_dis.h, asm_pyc.c
* removed unused classes argument from place_nodes in agraph.c
* removed unused recurse and recurse_bb functions in canalysis.c
* removed unused vars field from RzPrint struct
* removed unused RzAnalysisType* structs from rz_analysis.h
* removed unused list field from RzEgg struct
* fixed bug in bp_plugin.c where duplication-checking logic iterates over the wrong list
* removed unused q_regs field from RzDebug struct
* removed unused backtrace field from RzDebugPlugin struct
* removed unused classes_list field from RzBinNXOObj struct
* removed unused methods_list and classes_list fields from RzBinZimgObj struct
2022-09-11 13:04:53 +08:00
wargio
a73e8ecd4d Add references and flags to constant pointers to data maps 2022-08-13 22:52:24 +02:00
Peiwei Hu
0fc9c9682e
Fix some checks of rz_analysis_op (#2755)
* Fix some checks of rz_analysis_op
* rm unreachable code
2022-07-01 18:12:14 +08:00
Riccardo Schirone
2987e035da hash: use RzHash in most hash APIs 2022-06-28 21:55:26 +08:00
GustavoLCR
f10e5d865a Debug: Allow dce in all platforms
* Used for `WinKD` and `Windows` debug
2022-06-05 00:27:35 +08:00
Riccardo Schirone
962ffe2755 RzDebug/p/native: do not use ptrace with NT_X86_XSTATE if not supported
If the kernel/system where Rizin is currently run does not support
ptrace(PTRACE_GETREGSET, ..., NT_X86_XSTATE, ...), ENODEV is returned by
the kernel. In such cases, we print the error message once and never
execute the ptrace call again, assuming it is not supported.

Signed-off-by: Riccardo Schirone <sirmy15@gmail.com>
2022-04-05 14:14:35 +02:00
GustavoLCR
170ab3eb3b
Remove windows.h include from rz_types.h (#2410)
* Create `rz_windows.h`
* Move `RzThread` structure definitions to internal header
* Create and use `rz_th_get_user()` API to avoid exposing `RzThread` layout in external header
* Make `rz_th_self()` an IPI
* Use `_wmkdir()` in `rz_sys_mkdir()` on Windows
* Remove unused `winkd_break_read` function
* Remove `RzIORap` definition from `rz_io.h`
* Remove include of `Windows.h` from `rz_types.h`
* Use `rz_windows.h` when necessary
* Remove `RzCoreRtrHost` definition from `rz_core.h`
* Remove `rz_socket.h` include from `rz_core.h`
2022-03-16 13:54:41 +01:00
Florian Märkl
06ccd06197 Add unit tests for software breakpoints 2022-01-26 17:12:26 +01:00
Florian Märkl
3b0b966b29 Remove dbg.bpsize and instead calculate when needed
In practice, dbg.bpsize was always automatically set to
rz_bp_size(core->dbg->bp, core->analysis->bits) whenever the global bits
changed. But this breaks as soon as different bits are needed for where
the breakpoint is supposed to be set vs. the current value of asm.bits
(for example for thumb/arm32).
So this removes the global bpsize and always calculates it for the
specific breakpoint address.
As a sidenote, dbg.bpsize was not even used for manual db (for dcu it
was though).
2022-01-26 17:12:26 +01:00
Florian Märkl
7586e43625 Make breakpoint size respect address-specific bits
On thumb/arm, the current analysis->bits value may not be equal to the
bitness of code that a breakpoint is supposed to be set to. This caused
software breakpoints to be created with incorrect data.
Now the bits for an address is queried by bp through a callback instead
of using a global bp->bits value which would usually correspond to the
current seek, but not the breakpoint addr.
2022-01-26 17:12:26 +01:00
Florian Märkl
490fb69685 Refactor: Replace corebind by need-driven context in RzBreakpoint 2022-01-26 17:12:26 +01:00
Paul I
43aba6bec9
Fix memory leak in rz_debug_free() 2022-01-15 23:49:21 +08:00
Florian Märkl
b179a5f3c6 Refactor rz_debug_reg_get()/set()
* Logic for getting a register by role or name, whichever matches, moved
  to RzReg (rz_reg_get_by_role_or_name)
* Removed rz_debug_reg_err() because it's unnecessary
* Added rz_core_reg_getv_by_role_or_name() and
  rz_core_reg_aetv_by_role_or_name() to replace rz_debug_reg_get() for
  for usage whenever it is not debug-specific.
2021-12-21 13:14:08 +01:00
Riccardo Schirone
d8cd049652
Windows on non-x86 arch was still using non-existing RZ_BP defines (#2112) 2021-12-17 19:09:59 +01:00
Dhruv Maroo
3d6b7f0235
Cleanup dbl command handler; Remove rz_bp_list (#2012) 2021-11-25 22:33:24 +05:30
Dhruv Maroo
34d345d884 Format according to clang-format-13 2021-11-25 15:44:28 +08:00
GustavoLCR
53a7694631
Add support for Windows on ARM (#1502)
* Support building for Windows on ARM

* Fix usage of reserved function name on ARM
* Fix architecture dependent `CONTEXT` fields access

* Fixes for debugging on Windows on ARM

* Fix breakpoint behavior on windows on ARM
* Fix register profile when debugging
* Remove `drx` error message if not supported
* Add support for hardware breakpoints
* Disable support for hardware single-stepping

* Fix Windows Message breakpoints on ARM

* Fix software single-stepping on return instruction on ARM

* Consider link register as destination for return instructions

* Fix setting debug bits to 16

* Rename `r12` to `ip` for windows arm register profile

* Remove debug bits hardcoding on windows

* Add 32bit registers to Windows ARM64 register profile

* Fix software step breakpoint alignment when entering thumb mode

* Define `RZ_TEST_ARCH` for `arm` and `arm64`

* Use `StackWalk64` API for backtracing on Windows

* Fix software single-stepping ARM in thumb mode

* Sync `asm.bits` with debugger

* Cleanup windows_debug.c

* Add SPDX for cross-arm64-windows.txt

* Add floating point control register flags

* Fix Windows Arm register profile alignment

* Keep `drx` warning
2021-11-24 20:13:42 +08:00
Florian Märkl
2ee8d603f8
Do not ask about killing the process if it is impossible (#1914) 2021-11-01 14:03:27 +08:00
Florian Märkl
7aeff0fc51
[Debug] Let gdb attach regularly and reset reason after attach (#1913) 2021-10-31 21:23:36 +01:00
Dhruv Maroo
178701f721
Reduce registers shown in the output of dr and Vpp when analysing an ARM64 executable (#1739)
* Add function to check if a register is a system register

* Only checks for ARM64 system registers as of now

* Check for system registers in ARM64 when printing registers using "dr"

* Does not completely remove the unnecessary register, but removes a
  huge number of useless registers printed by "dr"

* Rename `RZ_REG_TYPE_ALL` to `RZ_REG_TYPE_ANY`

* ADd register types for "sys" and "pauth": `RZ_REG_TYPE_SYS` and
  `RZ_REG_TYPE_PAUTH` respectively

* Remove `rz_reg_is_system_reg`

* Add `sys` and `pauth` register profiles

* Update debug tests to account for new arenas and register profiles

* REplace "pauth" with "sec" reg profile

* Update integration tests to account for new register profiles: `sys`, `sec`
2021-09-28 23:49:55 +08:00
Dhruv Maroo
a527b204d8
Add API function for RzBreakpointItem and fix breakpoint serialization tests (#1750) 2021-09-26 10:17:13 +02:00
Giovanni
74a9ed8ba8
Fix various Coverity bugs (#1569)
* CID 316598: Logically dead code (DEADCODE)
* CID 315963: Resource leak (RESOURCE_LEAK)
* CID 316731: Logically dead code (DEADCODE)
* CID 316000: Logically dead code (DEADCODE)
* CID 315918: Logically dead code (DEADCODE)
* CID 315950: Logically dead code (DEADCODE)
* CID 315965: Logically dead code (DEADCODE)
* CID 316044: Logically dead code (DEADCODE)
* CID 316064: Logically dead code (DEADCODE)
* CID 316067: Structurally dead code (UNREACHABLE)
* CID 316077: Logically dead code (DEADCODE)
* CID 316083: Logically dead code (DEADCODE)
* CID 316165: Missing break in switch (MISSING_BREAK)
* CID 316202: Logically dead code (DEADCODE)
* CID 316206: Logically dead code (DEADCODE)
* CID 316230: Logically dead code (DEADCODE)
* CID 316234: Logically dead code (DEADCODE)
* CID 316241: Logically dead code (DEADCODE)
2021-09-02 14:10:00 +02:00
Anton Kochkov
abc1d79f95
Add missing copyrights (#1570)
* Add missing SPDX copyrights

* Fix include headers
2021-09-02 16:39:50 +08:00
Anton Kochkov
b9cb29ac90
Rename RNum to the RzNum (#1539) 2021-08-29 21:06:29 +02:00
GustavoLCR
b84158fd3e
Fixes for value analysis (#1520)
* Fill `op->reg` for ARM64 `br`/`blr` analysis
* This fixes software single-stepping on `br`/`blr` instructions on ARM64
* Fill `op->reg` for ARM `bx`/`blx` analysis
* This fixes software single-stepping on `bx`/`blx` instructions on ARM
* Set `bx` as `RZ_ANALYSIS_OP_TYPE_RJMP`
* Fill `RzAnalysisValue->type`
* Use only `RzAnalysisValue` in `rz_core_link_stroff()`
* Fill `op->ireg/disp/scale` for ARM `ldr` analysis
* This fixes software single-stepping for `ldr pc` on ARM
* Fix riscv inverted src/dst values for store instructions
* Fix riscv analysis with buffer of size 2
* Add unit tests for `RzAnalysisOp` and `RzAnalysisValue`

Co-authored-by: Giovanni <561184+wargio@users.noreply.github.com>
2021-08-27 22:07:39 +08:00
Florian Märkl
78652caaf5 Add user pointer to RzDebug Plugins and Refactor GDB for it 2021-06-14 11:46:17 +02:00
Riccardo Schirone
53bf5c497f SPDX Copyright text for all files based on history
- Add LICENSES directory
- Download additional licenses used
- Add .reuse directory
- Add doc about SPDX/reuse

Co-authored-by: Florian Märkl <info@florianmaerkl.de>
2021-03-05 19:39:15 +08:00
Paul I
8a69088719 Use HtUP for storing trace nodes 2021-03-01 18:47:53 +01:00
Alexis Ehret
35f6a1c53f Fix dead assignment librz/debug/debug.c 2021-02-09 10:37:25 -01:00