formatter ran
This commit is contained in:
parent
ce1cf27630
commit
0ed945af36
|
|
@ -183,7 +183,8 @@ namespace ElfBug
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
waited = waitpid(pid, &stepStatus, __WALL);
|
waited = waitpid(pid, &stepStatus, __WALL);
|
||||||
} while(waited == -1 && errno == EINTR);
|
}
|
||||||
|
while(waited == -1 && errno == EINTR);
|
||||||
if(waited == -1)
|
if(waited == -1)
|
||||||
{
|
{
|
||||||
cbInternalError("waitpid(step) failed: " + std::string(strerror(errno)));
|
cbInternalError("waitpid(step) failed: " + std::string(strerror(errno)));
|
||||||
|
|
|
||||||
|
|
@ -119,7 +119,8 @@ namespace ElfBug
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
n = read(pipeFds[0], errBuf, sizeof(errBuf) - 1);
|
n = read(pipeFds[0], errBuf, sizeof(errBuf) - 1);
|
||||||
} while(n == -1 && errno == EINTR);
|
}
|
||||||
|
while(n == -1 && errno == EINTR);
|
||||||
close(pipeFds[0]);
|
close(pipeFds[0]);
|
||||||
|
|
||||||
if(n == -1)
|
if(n == -1)
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,8 @@ namespace ElfBug::test
|
||||||
}
|
}
|
||||||
|
|
||||||
// /proc/<pid>/stat state char: R/S = scheduled, t/T = ptrace-stopped.
|
// /proc/<pid>/stat state char: R/S = scheduled, t/T = ptrace-stopped.
|
||||||
bool WaitForRunning(const std::chrono::milliseconds timeout = std::chrono::seconds(5)) const {
|
bool WaitForRunning(const std::chrono::milliseconds timeout = std::chrono::seconds(5)) const
|
||||||
|
{
|
||||||
const pid_t pid = mProcess ? mProcess->pid : 0;
|
const pid_t pid = mProcess ? mProcess->pid : 0;
|
||||||
if(pid <= 0) return false;
|
if(pid <= 0) return false;
|
||||||
const auto start = std::chrono::steady_clock::now();
|
const auto start = std::chrono::steady_clock::now();
|
||||||
|
|
@ -112,8 +113,8 @@ namespace ElfBug::test
|
||||||
Event WaitFor(EventType type, std::chrono::milliseconds timeout = std::chrono::seconds(5))
|
Event WaitFor(EventType type, std::chrono::milliseconds timeout = std::chrono::seconds(5))
|
||||||
{
|
{
|
||||||
return waitForPredicate(
|
return waitForPredicate(
|
||||||
[type](const Event & e) { return e.type == type; },
|
[type](const Event & e) { return e.type == type; },
|
||||||
timeout, "WaitFor timeout");
|
timeout, "WaitFor timeout");
|
||||||
}
|
}
|
||||||
|
|
||||||
Event WaitForSystemBreakpoint() { return WaitFor(EventType::SystemBreakpoint); }
|
Event WaitForSystemBreakpoint() { return WaitFor(EventType::SystemBreakpoint); }
|
||||||
|
|
@ -125,15 +126,15 @@ namespace ElfBug::test
|
||||||
Event WaitForException(int sig, const std::chrono::milliseconds timeout = std::chrono::seconds(5))
|
Event WaitForException(int sig, const std::chrono::milliseconds timeout = std::chrono::seconds(5))
|
||||||
{
|
{
|
||||||
return waitForPredicate(
|
return waitForPredicate(
|
||||||
[sig](const Event & e) { return e.type == EventType::Exception && e.signal == sig; },
|
[sig](const Event & e) { return e.type == EventType::Exception && e.signal == sig; },
|
||||||
timeout, "WaitForException timeout");
|
timeout, "WaitForException timeout");
|
||||||
}
|
}
|
||||||
|
|
||||||
Event WaitForBreakpointAt(ptr addr, const std::chrono::milliseconds timeout = std::chrono::seconds(5))
|
Event WaitForBreakpointAt(ptr addr, const std::chrono::milliseconds timeout = std::chrono::seconds(5))
|
||||||
{
|
{
|
||||||
return waitForPredicate(
|
return waitForPredicate(
|
||||||
[addr](const Event & e) { return e.type == EventType::Breakpoint && e.address == addr; },
|
[addr](const Event & e) { return e.type == EventType::Breakpoint && e.address == addr; },
|
||||||
timeout, "WaitForBreakpointAt timeout");
|
timeout, "WaitForBreakpointAt timeout");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
extern "C" __attribute__((noinline, used)) void hit_me() {
|
extern "C" __attribute__((noinline, used)) void hit_me()
|
||||||
|
{
|
||||||
asm volatile("nop");
|
asm volatile("nop");
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
std::puts("Hello, ElfBug!");
|
std::puts("Hello, ElfBug!");
|
||||||
hit_me();
|
hit_me();
|
||||||
hit_me();
|
hit_me();
|
||||||
|
|
|
||||||
|
|
@ -4,14 +4,16 @@
|
||||||
|
|
||||||
static std::atomic<int> gRanCount{0};
|
static std::atomic<int> gRanCount{0};
|
||||||
|
|
||||||
static void* worker(void*) {
|
static void* worker(void*)
|
||||||
|
{
|
||||||
gRanCount.fetch_add(1, std::memory_order_relaxed);
|
gRanCount.fetch_add(1, std::memory_order_relaxed);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
std::vector<pthread_t> threads(5);
|
std::vector<pthread_t> threads(5);
|
||||||
for (auto& t : threads) pthread_create(&t, nullptr, worker, nullptr);
|
for(auto& t : threads) pthread_create(&t, nullptr, worker, nullptr);
|
||||||
for (const auto& t : threads) pthread_join(t, nullptr);
|
for(const auto& t : threads) pthread_join(t, nullptr);
|
||||||
return gRanCount.load(std::memory_order_relaxed);
|
return gRanCount.load(std::memory_order_relaxed);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
volatile int i = 0;
|
volatile int i = 0;
|
||||||
while (true) { i = 42; }
|
while(true) { i = 42; }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
volatile int* p = reinterpret_cast<int*>(static_cast<std::uintptr_t>(0));
|
volatile int* p = reinterpret_cast<int*>(static_cast<std::uintptr_t>(0));
|
||||||
*p = 42;
|
*p = 42;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -156,7 +156,8 @@ TEST_CASE("Software breakpoint: persistent hits twice", "[breakpoint]")
|
||||||
|
|
||||||
std::promise<ResolvedBreakpoint> bpPromise;
|
std::promise<ResolvedBreakpoint> bpPromise;
|
||||||
auto bpFuture = bpPromise.get_future();
|
auto bpFuture = bpPromise.get_future();
|
||||||
dbg.OnSystemBreakpoint([&] {
|
dbg.OnSystemBreakpoint([&]
|
||||||
|
{
|
||||||
ResolvedBreakpoint bp;
|
ResolvedBreakpoint bp;
|
||||||
const auto resolved = ResolveRuntimeAddress(path, dbg.process()->pid, "hit_me");
|
const auto resolved = ResolveRuntimeAddress(path, dbg.process()->pid, "hit_me");
|
||||||
if(resolved)
|
if(resolved)
|
||||||
|
|
@ -207,7 +208,8 @@ TEST_CASE("Software breakpoint patches and restores instruction byte", "[breakpo
|
||||||
|
|
||||||
std::promise<BreakpointPatchRoundTrip> bpPromise;
|
std::promise<BreakpointPatchRoundTrip> bpPromise;
|
||||||
auto bpFuture = bpPromise.get_future();
|
auto bpFuture = bpPromise.get_future();
|
||||||
dbg.OnSystemBreakpoint([&] {
|
dbg.OnSystemBreakpoint([&]
|
||||||
|
{
|
||||||
BreakpointPatchRoundTrip bp;
|
BreakpointPatchRoundTrip bp;
|
||||||
const auto resolved = ResolveRuntimeAddress(path, dbg.process()->pid, "hit_me");
|
const auto resolved = ResolveRuntimeAddress(path, dbg.process()->pid, "hit_me");
|
||||||
if(resolved)
|
if(resolved)
|
||||||
|
|
@ -252,7 +254,8 @@ TEST_CASE("Software breakpoint: singleshot hits once", "[breakpoint]")
|
||||||
|
|
||||||
std::promise<ResolvedBreakpoint> bpPromise;
|
std::promise<ResolvedBreakpoint> bpPromise;
|
||||||
auto bpFuture = bpPromise.get_future();
|
auto bpFuture = bpPromise.get_future();
|
||||||
dbg.OnSystemBreakpoint([&] {
|
dbg.OnSystemBreakpoint([&]
|
||||||
|
{
|
||||||
ResolvedBreakpoint bp;
|
ResolvedBreakpoint bp;
|
||||||
const auto resolved = ResolveRuntimeAddress(path, dbg.process()->pid, "hit_me");
|
const auto resolved = ResolveRuntimeAddress(path, dbg.process()->pid, "hit_me");
|
||||||
if(resolved)
|
if(resolved)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue