mirror of
https://github.com/zevenet/pound.git
synced 2025-10-27 07:29:34 +00:00
debug: add decoded backtrace with file and line
Signed-off-by: Alvaro Cano <alvaro.cano@zevenet.com>
This commit is contained in:
parent
b9189f2e65
commit
f4a6c2507a
203
CMakeLists.txt
203
CMakeLists.txt
@ -1,161 +1,106 @@
|
||||
cmake_minimum_required(VERSION 3.7)
|
||||
cmake_minimum_required(VERSION 3.7)
|
||||
|
||||
project(pound_gitlab)
|
||||
project(pound_gitlab)
|
||||
|
||||
SET(MAINFOLDER ${PROJECT_SOURCE_DIR})
|
||||
|
||||
SET(MAINFOLDER ${PROJECT_SOURCE_DIR})
|
||||
#if (NOT EXECUTABLE_OUTPUT_PATH)
|
||||
# SET(EXECUTABLE_OUTPUT_PATH "${MAINFOLDER}/bin")
|
||||
#endif ()
|
||||
|
||||
#add_definitions(-DVERSION=\"pound2.8a+zevenet5\" -DC_SSL=\"\" -DC_T_RSA=\"0\" -DC_DH_LEN=\"2048\" -DC_MAXBUF=\"16384\" -DC_OWNER=\"\" -DC_GROUP=\"\" -DC_SUPER=\"0\" -DC_CERT1L=\"\" -Wstrict-prototypes -Wno-unused-result -pipe -pthread -DNEED_STACK -DHAVE_SYSLOG_H=1 -pthread -DDH_LEN=2048 -D_REENTRANT -D_THREAD_SAFE )
|
||||
add_definitions(-DVERSION=\"pound2.8a+zevenet5\" -DC_SSL=\"\" -DC_T_RSA=\"0\" -DC_DH_LEN=\"2048\" -DC_MAXBUF=\"16384\" -DC_OWNER=\"\" -DC_GROUP=\"\" -DC_SUPER=\"0\" -DC_CERT1L=\"\" -Wstrict-prototypes -Wno-unused-result -pipe -DNEED_STACK -DHAVE_SYSLOG_H=1 -DDH_LEN=2048 -DMAXBUF=16384 -D_REENTRANT -D_THREAD_SAFE) #
|
||||
add_definitions(-DWAF=1)
|
||||
|
||||
#if (NOT EXECUTABLE_OUTPUT_PATH)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -lresolv -rdynamic -lm -ldl ")
|
||||
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__FILENAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'")
|
||||
|
||||
# SET(EXECUTABLE_OUTPUT_PATH "${MAINFOLDER}/bin")
|
||||
|
||||
#endif ()
|
||||
#if (NOT CMAKE_BUILD_TYPE)
|
||||
# set(CMAKE_BUILD_TYPE Debug)
|
||||
#endif ()
|
||||
|
||||
|
||||
#add_definitions(-DVERSION=\"pound2.8a+zevenet5\" -DC_SSL=\"\" -DC_T_RSA=\"0\" -DC_DH_LEN=\"2048\" -DC_MAXBUF=\"16384\" -DC_OWNER=\"\" -DC_GROUP=\"\" -DC_SUPER=\"0\" -DC_CERT1L=\"\" -Wstrict-prototypes -Wno-unused-result -pipe -pthread -DNEED_STACK -DHAVE_SYSLOG_H=1 -pthread -DDH_LEN=2048 -D_REENTRANT -D_THREAD_SAFE )
|
||||
#set(CMAKE_C_FLAGS_DEBUG " -ldl -lresolv -g -rdynamic")
|
||||
#set(CMAKE_C_FLAGS_RELEASE "-O2 ")
|
||||
|
||||
add_definitions(-DVERSION=\"pound2.8a+zevenet5\" -DC_SSL=\"\" -DC_T_RSA=\"0\" -DC_DH_LEN=\"2048\" -DC_MAXBUF=\"16384\" -DC_OWNER=\"\" -DC_GROUP=\"\" -DC_SUPER=\"0\" -DC_CERT1L=\"\" -Wstrict-prototypes -Wno-unused-result -pipe -DNEED_STACK -DHAVE_SYSLOG_H=1 -DDH_LEN=2048 -DMAXBUF=16384 -D_REENTRANT -D_THREAD_SAFE) #
|
||||
add_definitions(-DWAF=1)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -lresolv -ldl -g -rdynamic -lm ")
|
||||
find_package(PkgConfig)
|
||||
|
||||
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__FILENAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'")
|
||||
pkg_check_modules(PC_PCRE QUIET libpcre)
|
||||
|
||||
set(PCRE_DEFINITIONS ${PC_PCRE_CFLAGS_OTHER})
|
||||
|
||||
#if (NOT CMAKE_BUILD_TYPE)
|
||||
find_path(PCRE_INCLUDE_DIR pcre.h
|
||||
HINTS ${PC_PCRE_INCLUDEDIR} ${PC_PCRE_INCLUDE_DIRS}
|
||||
PATH_SUFFIXES pcre)
|
||||
find_library(PCRE_PCRE_LIBRARY NAMES pcre HINTS ${PC_PCRE_LIBDIR} ${PC_PCRE_LIBRARY_DIRS})
|
||||
find_library(PCRE_PCREPOSIX_LIBRARY NAMES pcreposix HINTS ${PC_PCRE_LIBDIR} ${PC_PCRE_LIBRARY_DIRS})
|
||||
|
||||
# set(CMAKE_BUILD_TYPE Debug)
|
||||
|
||||
#endif ()
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(PCRE DEFAULT_MSG PCRE_INCLUDE_DIR PCRE_PCRE_LIBRARY PCRE_PCREPOSIX_LIBRARY)
|
||||
|
||||
set(PCRE_LIBRARIES ${PCRE_PCREPOSIX_LIBRARY} ${PCRE_PCRE_LIBRARY})
|
||||
|
||||
set(CMAKE_C_FLAGS_DEBUG "-g -rdynamic ")
|
||||
mark_as_advanced(PCRE_INCLUDE_DIR PCRE_LIBRARIES PCRE_PCRE_LIBRARY)
|
||||
|
||||
#set(CMAKE_C_FLAGS_RELEASE "-O2 ")
|
||||
|
||||
# Search OpenSSL
|
||||
#find_package(PkgConfig REQUIRED)
|
||||
#pkg_search_module(OPENSSL REQUIRED openssl)
|
||||
|
||||
find_package(PkgConfig)
|
||||
#if (OPENSSL_FOUND)
|
||||
# include_directories(${OPENSSL_INCLUDE_DIRS})
|
||||
# message(STATUS "Using OpenSSL ${OPENSSL_VERSION}")
|
||||
#else ()
|
||||
# # Error; with REQUIRED, pkg_search_module() will throw an error by it's own
|
||||
#endif ()
|
||||
|
||||
pkg_check_modules(PC_PCRE QUIET libpcre)
|
||||
|
||||
set(PCRE_DEFINITIONS ${PC_PCRE_CFLAGS_OTHER})
|
||||
find_package(PkgConfig REQUIRED)
|
||||
|
||||
find_path(PCRE_INCLUDE_DIR pcre.h
|
||||
pkg_search_module(OPENSSL REQUIRED openssl)
|
||||
|
||||
HINTS ${PC_PCRE_INCLUDEDIR} ${PC_PCRE_INCLUDE_DIRS}
|
||||
|
||||
PATH_SUFFIXES pcre)
|
||||
#if (OPENSSL_FOUND)
|
||||
# status_message(STATUS "Openssl includes ${OPENSSL_INCLUDE_DIRS}")
|
||||
# status_message(STATUS "Openssl link ${OPENSSL_LIBRARIES}")
|
||||
# include_directories(${OPENSSL_INCLUDE_DIRS})
|
||||
# status_message(STATUS "Using OpenSSL ${OPENSSL_VERSION}")
|
||||
|
||||
#else ()
|
||||
# Error; with REQUIRED, pkg_search_module() will throw an error by it's own
|
||||
#endif ()
|
||||
|
||||
find_library(PCRE_PCRE_LIBRARY NAMES pcre HINTS ${PC_PCRE_LIBDIR} ${PC_PCRE_LIBRARY_DIRS})
|
||||
|
||||
include_directories(/usr/local/modsecurity/include)
|
||||
include_directories(/usr/include/openssl-1.1)
|
||||
link_directories(/usr/local/modsecurity/lib)
|
||||
link_directories(/usr/lib/openssl-1.1)
|
||||
find_package(Threads)
|
||||
|
||||
find_library(PCRE_PCREPOSIX_LIBRARY NAMES pcreposix HINTS ${PC_PCRE_LIBDIR} ${PC_PCRE_LIBRARY_DIRS})
|
||||
add_executable(${PROJECT_NAME}ctl
|
||||
poundctl.c
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
waf.c
|
||||
config.c
|
||||
config.h
|
||||
# dh2048.h
|
||||
# dh512.h
|
||||
# dh1024.h
|
||||
http.c
|
||||
pound.c
|
||||
pound.h
|
||||
pound_sync.c
|
||||
pound_sync.h
|
||||
pound_sync_enum.h
|
||||
svc.c
|
||||
svc.h
|
||||
version.c
|
||||
)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
|
||||
find_package_handle_standard_args(PCRE DEFAULT_MSG PCRE_INCLUDE_DIR PCRE_PCRE_LIBRARY PCRE_PCREPOSIX_LIBRARY)
|
||||
|
||||
set(PCRE_LIBRARIES ${PCRE_PCREPOSIX_LIBRARY} ${PCRE_PCRE_LIBRARY})
|
||||
|
||||
mark_as_advanced(PCRE_INCLUDE_DIR PCRE_LIBRARIES PCRE_PCRE_LIBRARY)
|
||||
|
||||
|
||||
# Search OpenSSL
|
||||
|
||||
#find_package(PkgConfig REQUIRED)
|
||||
|
||||
#pkg_search_module(OPENSSL REQUIRED openssl)
|
||||
|
||||
|
||||
#if (OPENSSL_FOUND)
|
||||
|
||||
# include_directories(${OPENSSL_INCLUDE_DIRS})
|
||||
|
||||
# message(STATUS "Using OpenSSL ${OPENSSL_VERSION}")
|
||||
|
||||
#else ()
|
||||
|
||||
# # Error; with REQUIRED, pkg_search_module() will throw an error by it's own
|
||||
|
||||
#endif ()
|
||||
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
|
||||
pkg_search_module(OPENSSL REQUIRED openssl)
|
||||
|
||||
|
||||
#if (OPENSSL_FOUND)
|
||||
|
||||
# status_message(STATUS "Openssl includes ${OPENSSL_INCLUDE_DIRS}")
|
||||
|
||||
# status_message(STATUS "Openssl link ${OPENSSL_LIBRARIES}")
|
||||
|
||||
# include_directories(${OPENSSL_INCLUDE_DIRS})
|
||||
|
||||
# status_message(STATUS "Using OpenSSL ${OPENSSL_VERSION}")
|
||||
|
||||
#else ()
|
||||
|
||||
# # Error; with REQUIRED, pkg_search_module() will throw an error by it's own
|
||||
|
||||
#endif ()
|
||||
|
||||
#
|
||||
|
||||
include_directories(/usr/include/openssl-1.1)
|
||||
|
||||
include_directories(/usr/local/modsecurity/include)
|
||||
link_directories(/usr/local/modsecurity/lib)
|
||||
|
||||
link_directories(/usr/lib/openssl-1.1)
|
||||
|
||||
find_package(Threads)
|
||||
|
||||
|
||||
add_executable(${PROJECT_NAME}ctl
|
||||
|
||||
poundctl.c
|
||||
|
||||
)
|
||||
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
waf.c
|
||||
|
||||
config.c
|
||||
|
||||
config.h
|
||||
|
||||
# dh2048.h
|
||||
|
||||
# dh512.h
|
||||
# dh1024.h
|
||||
|
||||
http.c
|
||||
|
||||
pound.c
|
||||
|
||||
pound.h
|
||||
|
||||
pound_sync.c
|
||||
|
||||
pound_sync.h
|
||||
|
||||
pound_sync_enum.h
|
||||
|
||||
svc.c
|
||||
|
||||
svc.h
|
||||
|
||||
version.c
|
||||
|
||||
)
|
||||
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} ${PCRE_LIBRARIES} ${OPENSSL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} libmodsecurity.so)
|
||||
target_link_libraries(${PROJECT_NAME}ctl ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries(${PROJECT_NAME} ${PCRE_LIBRARIES} ${OPENSSL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} libmodsecurity.so)
|
||||
target_link_libraries(${PROJECT_NAME}ctl ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
||||
@ -25,7 +25,7 @@
|
||||
|
||||
#INCLUDES=-I/usr/local/modsecurity/include/ -L/usr/local/modsecurity/lib -Wl,-rpath=/usr/local/modsecurity/lib
|
||||
|
||||
CC=@PTHREAD_CC@ -g -rdynamic $(INCLUDES)
|
||||
CC=@PTHREAD_CC@ -g -ldl -rdynamic $(INCLUDES)
|
||||
|
||||
# TODO: add to configure
|
||||
C_WAF=-DWAF=1
|
||||
@ -33,7 +33,7 @@ C_WAF=-DWAF=1
|
||||
CFLAGS=-DF_CONF=\"@sysconfdir@/pound.cfg\" -DVERSION=\"@PACKAGE_VERSION@\" -DC_SSL=\"@C_SSL@\" -DC_T_RSA=\"@C_T_RSA@\" \
|
||||
-DC_DH_LEN=\"@C_DH_LEN@\" -DC_MAXBUF=\"@C_MAXBUF@\" -DC_OWNER=\"@C_OWNER@\" -DC_GROUP=\"@C_GROUP@\" \
|
||||
-DC_SUPER=\"@C_SUPER@\" -DC_CERT1L=\"@C_CERT1L@\" @CFLAGS@ @PTHREAD_CFLAGS@ @CPPFLAGS@ ${C_WAF}
|
||||
LIBS=@LIBS@ @PTHREAD_LIBS@ -lmodsecurity
|
||||
LIBS=@LIBS@ @PTHREAD_LIBS@ -lmodsecurity -ldl
|
||||
|
||||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
|
||||
93
pound.c
93
pound.c
@ -27,7 +27,7 @@
|
||||
|
||||
#include "pound.h"
|
||||
#include "pound_sync.h"
|
||||
#include <execinfo.h>
|
||||
|
||||
|
||||
/* common variables */
|
||||
char *conf_name;
|
||||
@ -192,7 +192,7 @@ thr_arg *get_thr_arg(void)
|
||||
/*
|
||||
* get the current queue length
|
||||
*/
|
||||
get_thr_qlen(void)
|
||||
int get_thr_qlen(void)
|
||||
{
|
||||
int res;
|
||||
thr_arg *tap;
|
||||
@ -237,28 +237,6 @@ static RETSIGTYPE h_shut(const int sig)
|
||||
shut_down = 1;
|
||||
}
|
||||
|
||||
void handler(int sig)
|
||||
{
|
||||
void *array[100];
|
||||
char **strings;
|
||||
int j, nptrs;
|
||||
|
||||
// get void*'s for all entries on the stack
|
||||
nptrs = backtrace(array, 10);
|
||||
// print out all the frames to stderr
|
||||
logmsg(LOG_ERR, "Error: signal %d:\n", sig);
|
||||
strings = backtrace_symbols(array, nptrs);
|
||||
if (strings == NULL) {
|
||||
logmsg(LOG_ERR, "backtrace_symbols");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
for (j = 0; j < nptrs; j++)
|
||||
logmsg(LOG_ERR, "backtrace_symbols: %s", strings[j]);
|
||||
free(strings);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
// data to waf log output
|
||||
static void logmsg_cb(void *data, const void *message)
|
||||
@ -266,6 +244,72 @@ static void logmsg_cb(void *data, const void *message)
|
||||
logmsg(LOG_INFO, "%s", (const char *) message);
|
||||
}
|
||||
|
||||
/**** BACKTRACE ****/
|
||||
|
||||
size_t ConvertToVMA(size_t addr)
|
||||
{
|
||||
Dl_info info;
|
||||
struct link_map *link_map;
|
||||
dladdr1((void *)addr, &info, (void **)&link_map, RTLD_DL_LINKMAP);
|
||||
return addr - link_map->l_addr;
|
||||
}
|
||||
|
||||
void zcu_bt_print(void)
|
||||
{
|
||||
void *callstack[128];
|
||||
int frame_count =
|
||||
backtrace(callstack, sizeof(callstack) / sizeof(callstack[0]));
|
||||
FILE *fp;
|
||||
char path[ZCU_DEF_BUFFER_SIZE];
|
||||
|
||||
if (!frame_count) {
|
||||
logmsg(LOG_ERR, "No backtrace strings found!");
|
||||
exit(EXIT_FAILURE);
|
||||
} else {
|
||||
for (int i = 0; i < frame_count; i++) {
|
||||
Dl_info info;
|
||||
if (dladdr(callstack[i], &info)) {
|
||||
char command[256];
|
||||
size_t VMA_addr =
|
||||
ConvertToVMA((size_t)callstack[i]);
|
||||
VMA_addr -=
|
||||
1; // https://stackoverflow.com/questions/11579509/wrong-line-numbers-from-addr2line/63841497#63841497
|
||||
snprintf(command, sizeof(command),
|
||||
"addr2line -e %s -Ci %zx",
|
||||
info.dli_fname, VMA_addr);
|
||||
|
||||
/* Open the command for reading. */
|
||||
fp = popen(command, "r");
|
||||
if (fp == NULL) {
|
||||
logmsg(LOG_ERR,
|
||||
"Failed to run: %s",
|
||||
command);
|
||||
exit(EXIT_FAILURE);
|
||||
} else {
|
||||
/* Read the output a line at a time - output it. */
|
||||
while (fgets(path, sizeof(path), fp) !=
|
||||
NULL) {
|
||||
printf("%s", path);
|
||||
}
|
||||
|
||||
logmsg(LOG_ERR, "Backtrace: %s",
|
||||
path);
|
||||
|
||||
/* close */
|
||||
pclose(fp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void handler(int sig)
|
||||
{
|
||||
logmsg(LOG_ERR, "Error: signal %d", sig);
|
||||
zcu_bt_print();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Pound: the reverse-proxy/load-balancer
|
||||
@ -273,7 +317,6 @@ static void logmsg_cb(void *data, const void *message)
|
||||
* Arguments:
|
||||
* -f config_file configuration file - exclusive of other flags
|
||||
*/
|
||||
|
||||
int main(const int argc, char **argv)
|
||||
{
|
||||
int n_listeners, i, clnt_length, clnt;
|
||||
|
||||
9
pound.h
9
pound.h
@ -27,6 +27,10 @@
|
||||
|
||||
#ifndef POUND_H
|
||||
#define POUND_H
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <link.h>
|
||||
|
||||
#include "config.h"
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
@ -252,7 +256,6 @@
|
||||
#ifndef __STDC__
|
||||
#define const
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LONG_LONG_INT
|
||||
#define LONG long long
|
||||
#define L0 0LL
|
||||
@ -358,6 +361,8 @@ extern int SOL_TCP;
|
||||
#endif
|
||||
#define MAXADDRBUFF 4096
|
||||
#define MAXHEADERS 128
|
||||
#define ZCU_DEF_BUFFER_SIZE 4096
|
||||
|
||||
|
||||
#ifndef F_CONF
|
||||
#define F_CONF "/usr/local/etc/pound.cfg"
|
||||
@ -606,7 +611,7 @@ extern thr_arg *get_thr_arg(void);
|
||||
/*
|
||||
* get the current queue length
|
||||
*/
|
||||
extern get_thr_qlen(void);
|
||||
extern int get_thr_qlen(void);
|
||||
|
||||
/*
|
||||
* handle an HTTP request
|
||||
|
||||
Loading…
Reference in New Issue
Block a user