debugbreak | break into the debugger | Code Inspection library
kandi X-RAY | debugbreak Summary
kandi X-RAY | debugbreak Summary
[debugbreak.h] allows you to put breakpoints in your C/C++ code with a call to debug_break():. License: the very permissive [2-Clause BSD] Known Problem: if continuing execution after a debugbreak breakpoint hit doesn’t work (e.g. on ARM or POWER), see [HOW-TO-USE-DEBUGBREAK-GDB-PY.md] HOW-TO-USE-DEBUGBREAK-GDB-PY.md) for a workaround.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Invoke debugger
- Parse GDB show version string
- Return the jump length of a breakpoint instruction
- Debug breakpoint
- Return the name of the target
- Invoke the debugger
- Continue the debugger
debugbreak Key Features
debugbreak Examples and Code Snippets
Community Discussions
Trending Discussions on debugbreak
QUESTION
I thought hot-patching assumed that overwriting any instruction that is 2 or more bytes long with a 2 byte jump is safe for concurrent execution of the same code.
So instruction fetch is assumed to be atomic.
Is it indeed atomic, taking into account that with prefixes it is possible to have more than 8 bytes instruction, and it can cross any aligned boundary? (Or does hot-patching rely on 16-byte alignment of function start? If so, what's with size over 8 bytes, anyway?)
The context: LLVM has interception of API functions in https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/interception/interception_win.cpp. This is used at least for Address Sanitizer, maybe for something else too. It implements HotPatch as 3rd method (line 61):
...ANSWER
Answered 2021-Dec-05 at 00:12Instruction fetch is not architecturally guaranteed to be atomic. Although, in practice, an instruction cache fill transaction is, by definition atomic, meaning that the line being filled in the cache cannot change before the transaction completes (which happens when the whole line is stored in the IFU, but not necessarily in the instruction cache itself). The instruction bytes are also delivered to the input buffer of the instruction predecode unit at some atomic granularity. On modern Intel processors, the instruction cache line size is 64 bytes and the input width of the predcode unit is 16 bytes with an address aligned on a 16-byte boundary. (Note that the 16 bytes input can be delivered to the predecode unit before the entire transaction of fetching the cache line containing these 16 bytes completes.) Therefore, an instruction aligned on a 16-byte boundary is guaranteed to be fetched atomically, together with at least one byte of the following contiguous instruction, depending on the size of the instruction. But this is a microarchitectural guarantee, not architectural.
It seems to me that by instruction fetch atomicity you're referring to atomicity at the granularity of individual instructions, rather than some fixed number of bytes. Either way, instruction fetch atomicity is not required for hotpatching to work correctly. It's actually impractical because instruction boundaries are not known at the time of fetch.
If instruction fetch is atomic, it may still be possible to fetch, execute, and retire the instruction being modified with only one of the two bytes being written (or none of the bytes or both of the bytes). The allowed orders in which writes reach GO depend on the effective memory types of the target memory locations. So hotpatching would still not be safe.
Intel specifies in Section 8.1.3 of the SDM V3 how self-modifying code (SMC) and cross-modifying code (XMC) should work to guarantee correctness on all Intel processors. Regarding SMC, it says the following:
To write self-modifying code and ensure that it is compliant with current and future versions of the IA-32 architectures, use one of the following coding options:
(* OPTION 1 *)
Store modified code (as data) into code segment;
Jump to new code or an intermediate location;
Execute new code;(* OPTION 2 *)
Store modified code (as data) into code segment;
Execute a serializing instruction; (* For example, CPUID instruction *)
Execute new code;The use of one of these options is not required for programs intended to run on the Pentium or Intel486 processors, but are recommended to ensure compatibility with the P6 and more recent processor families.
Note that the last statement is incorrect. The writer probably intended to say instead: "The use of one of these options is not required for programs intended to run on the Pentium or later processors, but are recommended to ensure compatibility with the Intel486 processors." This is explained in Section 11.6, from which I want to quote an important statement:
A write to a memory location in a code segment that is currently cached in the processor causes the associated cache line (or lines) to be invalidated. This check is based on the physical address of the instruction. In addition, the P6 family and Pentium processors check whether a write to a code segment may modify an instruction that has been prefetched for execution. If the write affects a prefetched instruction, the prefetch queue is invalidated. This latter check is based on the linear address of the instruction
Briefly, prefetch buffers are used to maintain instruction fetch requests and their results. Starting with the P6, they were replaced with streaming buffers, which have a different design. The manual still uses the term "prefetch buffers" for all processors. The important point here is that, with respect to what is guaranteed architecturally, the check in the prefetch buffers is done using linear addresses, not physical addresses. That said, probably all Intel processors do these checks using physical addresses, which can be proved experimentally. Otherwise, this can break the fundamental sequential program order guarantee. Consider the following sequence of operations being executed on the same processor:
QUESTION
I'm trying to use OpenTrace and ProcessTrace to read the events of a .etl
file.
- the call to OpenTrace successfully returns a
TRACEHANDLE
- the call to ProcessTrace returns
ERROR_SUCCESS
- but ProcessTrace never calls my
EVENT_CALLBACK
callback function
I know it's a valid .etl
file, because i can open it in:
Microsoft provides sample code on reading the events of a .etl
file. The basic gist is:
Initialize an
...EVENT_TRACE_LOGFILE
structure with the filename we want to open, and the address of our callback function. The callback function is called once for every event in the file:
ANSWER
Answered 2021-Nov-01 at 19:14The answer is exactly what I knew it would be.
- i started with headers translated by Franck Soranio
- where some definitions were
packed record
s - when that didn't work, I tried adding
$ALIGN 8
- the ABI required by Windows - when that didn't work, I tried adding
packed
to all records
When that didn't work, i asked Stackoverflow.
In the meantime, i spun up Visual Studio C++, and compared the sizeof
of the original structures, and the Delphi translations.
They didn't match.
The problem was the packed
records.
sizeof(EVENT_TRACE_LOGFILEW)
: 416 bytes (was 404)sizeof(EVENT_TRACE)
: 88 bytes (was 80)sizeof(EVENT_TRACE_HEADER)
: 44 bytes (was 40)
sizeof(TRACE_LOGFILE_HEADER
): 272 bytes
Removing the record packing fixed it.
QUESTION
In MASM, I've always inserted a standalone break instruction
...ANSWER
Answered 2021-Oct-27 at 14:58MSVC generates 2 byte nop before any single-byte instruction at the beginning of a function (except ret
in empty functions). I've tried __halt
, _enable
, _disable
intrinsics and seen the same effect.
Apparently it is for patching. /hotpatch
option gives the same change for x86, and /hotpatch
option is not recognized on x64. According to the /hotpatch
documentation, it is expected behavior (emphasis mine):
Because instructions are always two bytes or larger on the ARM architecture, and because x64 compilation is always treated as if /hotpatch has been specified, you don't have to specify /hotpatch when you compile for these targets;
So hotpatching support is unconditional for x64, and its result is seen in DebugBreak
implementation.
See here: https://godbolt.org/z/1G737cErf
See this post on why it is needed for hotpatching: Why do Windows functions all begin with a pointless MOV EDI, EDI instruction?. Looks like that currently hotpatching is smart enough to use any two bytes or more instruction, not just MOV EDI, EDI
, still it cannot use single-byte instruction, as two-byte backward jump may be written at exact moment when the instruction pointer points at the second instruction.
QUESTION
Is there a way to do something like DebugBreak() where when that function is hit the debugger breaks, but continue running when no debugger is attached?
I have a lua error handler that presents a user-friendly error message when something goes wrong, but if I'm debugging I want to stop execution as soon as I've detected something wrong.
I don't want to set a breakpoint in the debugger UI. I want a line of code that causes the debugger to break so I can share this breakpoint with co-workers.
...ANSWER
Answered 2021-Aug-05 at 22:31You can use IsDebuggerPresent
to check for an attached debugger, and then conditionally invoke DebugBreak
:
QUESTION
Using WinDbg Preview or WinDbg from Windows 10 SDK, when launching 32-bit process on Windows 10 1909 (build 18363.815) setting a breakpoint on kernelbase!RegOpenKeyExW by name doesn't work.
Example:
- Launch C:\windows\syswow64\notepad.exe under WinDbg
- .symfix C:\symbols
- .reload
- bp ntdll!NtOpenKeyEx
- g
- k
ANSWER
Answered 2020-May-01 at 19:25well one is CLRTYPE private symbol I don't know how it crept in but iirc there are few more symbols like this
use .symopt+4000 to load only public symbols then your breakpoint will be set correctly
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install debugbreak
You can use debugbreak like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page