Skip to content

Commit 30f5c5a

Browse files
committed
|add STOP variable for debugging
1 parent 7d9e3ef commit 30f5c5a

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/ipc/interfaces.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
#include <tinyformat.h>
1313
#include <util/system.h>
1414

15+
#include <boost/algorithm/string.hpp>
1516
#include <functional>
1617
#include <memory>
18+
#include <signal.h>
1719
#include <stdexcept>
1820
#include <stdio.h>
1921
#include <stdlib.h>
@@ -25,6 +27,28 @@
2527

2628
namespace ipc {
2729
namespace {
30+
//! Send stop signal to current process to aid debugging if directed by STOP
31+
//! environment variable.
32+
void DebugStop(const char* exe_name, int argc, char* argv[])
33+
{
34+
FILE* gdb = fsbridge::fopen("/tmp/gdb.txt", "a");
35+
fprintf(gdb, "%i %s\n", getpid(), argv[0]);
36+
fclose(gdb);
37+
if (const char* env_stop = getenv("STOP")) {
38+
std::string stop = env_stop;
39+
std::vector<std::string> stops;
40+
if (stop.size()) boost::split(stops, stop, boost::is_space(), boost::token_compress_on);
41+
for (const auto& s : stops) {
42+
if (strstr(exe_name, s.c_str())) {
43+
printf("Pid %i stopping for GDB\n", getpid());
44+
printf("sudo gdb -ex c %s %i\n", argv[0], getpid());
45+
raise(SIGSTOP);
46+
break;
47+
}
48+
}
49+
}
50+
}
51+
2852
class IpcImpl : public interfaces::Ipc
2953
{
3054
public:
@@ -47,6 +71,7 @@ class IpcImpl : public interfaces::Ipc
4771
}
4872
bool startSpawnedProcess(int argc, char* argv[], int& exit_status) override
4973
{
74+
DebugStop(m_exe_name, argc, argv);
5075
exit_status = EXIT_FAILURE;
5176
int32_t fd = -1;
5277
if (!m_process->checkSpawned(argc, argv, fd)) {

test/lint/lint-locale-dependence.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ KNOWN_VIOLATIONS=(
4444
"src/dbwrapper.cpp:.*vsnprintf"
4545
"src/httprpc.cpp.*trim"
4646
"src/init.cpp:.*atoi"
47+
"src/ipc/interfaces.cpp:.*is_space"
48+
"src/ipc/interfaces.cpp:.*printf"
4749
"src/qt/rpcconsole.cpp:.*atoi"
4850
"src/rest.cpp:.*strtol"
4951
"src/test/dbwrapper_tests.cpp:.*snprintf"

0 commit comments

Comments
 (0)