aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/common.h
diff options
context:
space:
mode:
authorGravatar Kurtis Rader <krader@skepticism.us>2016-05-15 19:45:02 -0700
committerGravatar Kurtis Rader <krader@skepticism.us>2016-05-17 14:52:55 -0700
commit73f2992a2e9ef1c96d45d9e90cc5e1f63a0afc92 (patch)
treecd32803426e1abf4910ecdbad333c2b19af46d2c /src/common.h
parentd55113b5b5e242b1ccfd7d8c916c38b7092b0bd3 (diff)
make debug() output more useful
This change does several things. First, and most important, it allows dumping the "n" most recent stack frames on each debug() call. Second, it demangles the C++ symbols. Third, it prepends each debug() message with the debug level. Unrelated to the above I've replaced all `assert(!is_forked_child());` statements with `ASSERT_IS_NOT_FORKED_CHILD()` for consistency.
Diffstat (limited to 'src/common.h')
-rw-r--r--src/common.h17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/common.h b/src/common.h
index 3d1a771f..ea0805f0 100644
--- a/src/common.h
+++ b/src/common.h
@@ -175,6 +175,9 @@ extern wchar_t omitted_newline_char;
/// it will not be printed.
extern int debug_level;
+/// How many stack frames to show when a debug() call is made.
+extern int debug_stack_frames;
+
/// Profiling flag. True if commands should be profiled.
extern bool g_profiling_active;
@@ -192,7 +195,7 @@ void write_ignore(int fd, const void *buff, size_t count);
if (!(arg)) { \
debug(0, "function %s called with null value for argument %s. ", __func__, #arg); \
bugreport(); \
- show_stackframe(); \
+ show_stackframe(L'E'); \
return retval; \
}
@@ -200,7 +203,7 @@ void write_ignore(int fd, const void *buff, size_t count);
#define FATAL_EXIT() \
{ \
char exit_read_buff; \
- show_stackframe(); \
+ show_stackframe(L'E'); \
read_ignore(0, &exit_read_buff, 1); \
exit_without_destructors(1); \
}
@@ -219,7 +222,7 @@ void write_ignore(int fd, const void *buff, size_t count);
if (signal_is_blocked()) { \
debug(0, "function %s called while blocking signals. ", __func__); \
bugreport(); \
- show_stackframe(); \
+ show_stackframe(L'E'); \
return retval; \
}
@@ -234,7 +237,7 @@ void write_ignore(int fd, const void *buff, size_t count);
#define contains(str, ...) contains_internal(str, 0, __VA_ARGS__, NULL)
/// Print a stack trace to stderr.
-void show_stackframe();
+void show_stackframe(const wchar_t msg_level, int frame_count = -1, int skip_levels = 0);
/// Read a line from the stream f into the string. Returns the number of bytes read or -1 on
/// failure.
@@ -485,8 +488,6 @@ class null_terminated_array_t {
void convert_wide_array_to_narrow(const null_terminated_array_t<wchar_t> &arr,
null_terminated_array_t<char> *output);
-bool is_forked_child();
-
class mutex_lock_t {
public:
pthread_mutex_t mutex;
@@ -668,8 +669,8 @@ ssize_t read_loop(int fd, void *buff, size_t count);
///
/// will print the string 'fish: Pi = 3.141', given that debug_level is 1 or higher, and that
/// program_name is 'fish'.
-void debug(int level, const char *msg, ...);
-void debug(int level, const wchar_t *msg, ...);
+void __attribute__((noinline)) debug(int level, const char *msg, ...);
+void __attribute__((noinline)) debug(int level, const wchar_t *msg, ...);
/// Replace special characters with backslash escape sequences. Newline is replaced with \n, etc.
///