Skip to content

Commit

Permalink
(#1307) Init version of snapshot logic
Browse files Browse the repository at this point in the history
- replace `SCOPE_ERROR_SIGNAL_HANDLER` with snapshot

Closes: #1307
  • Loading branch information
michalbiesek committed Feb 2, 2023
1 parent 6ee3631 commit a2ecd5d
Show file tree
Hide file tree
Showing 22 changed files with 537 additions and 449 deletions.
14 changes: 14 additions & 0 deletions docs/Snapshot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Snapshot information

TODO describe idea
TODO describe what information in which format files contain
TODO this is an interface description between CLI and library

Snapshot file details
```
/tmp/appscope/<PID>
│ info <mandatory>
│ cfg <mandatory>
│ coredump <optional>
| backtrace <optional>
```
2 changes: 1 addition & 1 deletion os/linux/aarch64.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ARCH_OBJ=$(ARCH)
LD_FLAGS=$(MUSL_AR) $(UNWIND_AR) $(COREDUMPER_AR) $(PCRE2_AR) $(LS_HPACK_AR) $(YAML_AR) $(JSON_AR) -ldl -lpthread -lrt -lresolv -Lcontrib/build/funchook -lfunchook -Lcontrib/build/funchook/capstone_src-prefix/src/capstone_src-build -lcapstone -z noexecstack
INCLUDES=-I./contrib/libyaml/include -I./contrib/cJSON -I./os/$(OS) -I./contrib/pcre2/src -I./contrib/build/pcre2 -I./contrib/funchook/capstone_src/include/ -I./contrib/jni -I./contrib/jni/linux/ -I./contrib/openssl/include -I./contrib/build/openssl/include -I./contrib/build/libunwind/include -I./contrib/libunwind/include/ -I./contrib/coredumper/src

$(LIBSCOPE): src/wrap.c src/state.c src/httpstate.c src/metriccapture.c src/report.c src/httpagg.c src/plattime.c src/fn.c os/$(OS)/os.c src/cfgutils.c src/cfg.c src/transport.c src/backoff.c src/log.c src/mtc.c src/circbuf.c src/linklist.c src/evtformat.c src/ctl.c src/mtcformat.c src/com.c src/scopestdlib.c src/dbg.c src/search.c src/wrap_go.c src/sysexec.c src/gocontext_arm.S src/scopeelf.c src/utils.c src/strset.c src/javabci.c src/javaagent.c src/ipc.c src/ipc_resp.c src/signalhandler.c src/coredump.c
$(LIBSCOPE): src/wrap.c src/state.c src/httpstate.c src/metriccapture.c src/report.c src/httpagg.c src/plattime.c src/fn.c os/$(OS)/os.c src/cfgutils.c src/cfg.c src/transport.c src/backoff.c src/log.c src/mtc.c src/circbuf.c src/linklist.c src/evtformat.c src/ctl.c src/mtcformat.c src/com.c src/scopestdlib.c src/dbg.c src/search.c src/wrap_go.c src/sysexec.c src/gocontext_arm.S src/scopeelf.c src/utils.c src/strset.c src/javabci.c src/javaagent.c src/ipc.c src/ipc_resp.c src/snapshot.c src/coredump.c
@$(MAKE) -C contrib funchook pcre2 openssl ls-hpack musl libyaml libunwind cJSON coredumper
@echo "$${CI:+::group::}Building $@"
$(CC) $(LIBRARY_CFLAGS) $(ARCH_CFLAGS) \
Expand Down
2 changes: 1 addition & 1 deletion os/linux/x86_64.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ INCLUDES=-I./contrib/libyaml/include -I./contrib/cJSON -I./os/$(OS) -I./contrib/
# objcopy -I binary -O elf64-x86-64 -B i386 ./lib/$(OS)/libscope.so ./lib/$(OS)/libscope.o && \
# rm -f ./lib/$(OS)/libscope.so

$(LIBSCOPE): src/wrap.c src/state.c src/httpstate.c src/metriccapture.c src/report.c src/httpagg.c src/plattime.c src/fn.c os/$(OS)/os.c src/cfgutils.c src/cfg.c src/transport.c src/backoff.c src/log.c src/mtc.c src/circbuf.c src/linklist.c src/evtformat.c src/ctl.c src/mtcformat.c src/com.c src/scopestdlib.c src/dbg.c src/search.c src/sysexec.c src/gocontext.S src/scopeelf.c src/wrap_go.c src/utils.c src/strset.c src/javabci.c src/javaagent.c src/ipc.c src/ipc_resp.c src/signalhandler.c src/coredump.c
$(LIBSCOPE): src/wrap.c src/state.c src/httpstate.c src/metriccapture.c src/report.c src/httpagg.c src/plattime.c src/fn.c os/$(OS)/os.c src/cfgutils.c src/cfg.c src/transport.c src/backoff.c src/log.c src/mtc.c src/circbuf.c src/linklist.c src/evtformat.c src/ctl.c src/mtcformat.c src/com.c src/scopestdlib.c src/dbg.c src/search.c src/sysexec.c src/gocontext.S src/scopeelf.c src/wrap_go.c src/utils.c src/strset.c src/javabci.c src/javaagent.c src/ipc.c src/ipc_resp.c src/snapshot.c src/coredump.c
@$(MAKE) -C contrib funchook pcre2 openssl ls-hpack musl libyaml cJSON libunwind coredumper
@echo "$${CI:+::group::}Building $@"
$(CC) $(LIBRARY_CFLAGS) $(ARCH_CFLAGS) \
Expand Down
24 changes: 8 additions & 16 deletions src/coredump.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,17 @@
#include "utils.h"
#include "google/coredumper.h"


/*
* Generates core dump in location based on <pathPrefix><pid>
* Generates core dump in location specifed by path
*
* Developer note: `WriteCoreDump` internally used PTRACE_ATTACH.
* If You try to observe behavior of `WriteCoreDump` function
* using GDB You will receive different result than in normal run.
* Ref: Schrödinger's cat
*
* Return status of operation
*/
bool
coreDumpGenerate(const char *pathPrefix, size_t pathPrefixSize, pid_t pid) {
char path[PATH_MAX] = {0};
if (pathPrefixSize > PATH_MAX) {
return FALSE;
}
scope_memcpy(path, pathPrefix, pathPrefixSize);
char pidBuf[32] = {0};
int msgLen = 0;
sigSafeUtoa(pid, pidBuf, 10, &msgLen);
if (pathPrefixSize + msgLen > PATH_MAX) {
return FALSE;
}
scope_memcpy(path + pathPrefixSize, pidBuf, msgLen);

coreDumpGenerate(const char *path) {
return (WriteCoreDump(path) == 0);
}
2 changes: 1 addition & 1 deletion src/coredump.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

#include "scopetypes.h"

bool coreDumpGenerate(const char *, size_t, pid_t);
bool coreDumpGenerate(const char *);

#endif // __COREDUMP_H__
9 changes: 0 additions & 9 deletions src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,6 @@ logSend(log_t* log, const char* msg, cfg_log_level_t mlevel)
return transportSend(log->transport, msg, scope_strlen(msg));
}

int
logSigSafeSendWithLen(log_t *log, const char *msg, size_t msgLen, cfg_log_level_t mlevel) {
if (!log || !msg) return -1;

if ((log->level == CFG_LOG_NONE) || (log->level > mlevel)) return 0;

return transportSigSafeSend(log->transport, msg, msgLen);
}

cfg_log_level_t
logLevel(log_t* log)
{
Expand Down
1 change: 0 additions & 1 deletion src/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ void logDestroy(log_t **);

// Accessors
int logSend(log_t *, const char *, cfg_log_level_t);
int logSigSafeSendWithLen(log_t *, const char *, size_t, cfg_log_level_t);
cfg_log_level_t logLevel(log_t *);
void logFlush(log_t *);
transport_status_t logConnectionStatus(log_t *);
Expand Down
4 changes: 0 additions & 4 deletions src/scopetypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,6 @@ typedef struct
// SCOPE_PAYLOAD_HEADER write payload headers to files
// SCOPE_PAYLOAD_TO_DISK if payloads are enabled, "true" forces writes to payload->dir
// SCOPE_ALLOW_CONSTRUCT_DBG allows debug inside the constructor
// SCOPE_ERROR_SIGNAL_HANDLER allows to register signal error handler for following signals: SIGSEGV, SIGBUS, SIGILL and SIGFPE
// "log" - log the backtrace
// "coredump" - generate coredump file as "/tmp/scope_core.<pid>"
// "full" - includes "log" and "coredump" functionality
// SCOPE_QUEUE_LENGTH override default circular buffer sizes
// SCOPE_START_NOPROFILE cause the start command to ignore updates to /etc/profile.d
// SCOPE_START_FORCE_PROFILE force the start command to update profile.d with a dev version
Expand Down
253 changes: 0 additions & 253 deletions src/signalhandler.c

This file was deleted.

20 changes: 0 additions & 20 deletions src/signalhandler.h

This file was deleted.

Loading

0 comments on commit a2ecd5d

Please sign in to comment.