From 14e283ff4e0656327179a5b69954796af3807b66 Mon Sep 17 00:00:00 2001 From: Vladimir Mezentsev Date: Thu, 16 Jun 2022 12:31:05 -0700 Subject: gprofng: fix build with -Werror=format-truncation gprofng/ChangeLog 2022-06-16 Vladimir Mezentsev * configure.ac: Remove -Wno-format-truncation. * src/Makefile.am: Likewise. * configure: Rebuild. * src/Makefile.in: Rebuild. * common/hwctable.c: Fix -Werror=format-truncation errors. * src/ipc.cc: Likewise. * src/parse.cc: Likewise. --- gprofng/src/Makefile.am | 1 - gprofng/src/Makefile.in | 1 - gprofng/src/ipc.cc | 45 +++++++++++++-------------------------------- gprofng/src/parse.cc | 7 +++++-- 4 files changed, 18 insertions(+), 36 deletions(-) (limited to 'gprofng/src') diff --git a/gprofng/src/Makefile.am b/gprofng/src/Makefile.am index 0718ab6..f2bd0a0 100644 --- a/gprofng/src/Makefile.am +++ b/gprofng/src/Makefile.am @@ -109,7 +109,6 @@ AM_CPPFLAGS = $(GPROFNG_CPPFLAGS) -DLOCALEDIR=\"@localedir@\" -I.. -I$(srcdir) \ -I$(srcdir)/../../include -I$(srcdir)/../../opcodes \ -I../../bfd -I$(srcdir)/../../bfd $(ZLIBINC) AM_CFLAGS = $(GPROFNG_CFLAGS) $(PTHREAD_CFLAGS) \ - $(GPROFNG_NO_FORMAT_TRUNCATION_CFLAGS) \ $(GPROFNG_NO_SWITCH_CFLAGS) AM_CXXFLAGS = $(AM_CFLAGS) diff --git a/gprofng/src/Makefile.in b/gprofng/src/Makefile.in index 1de9b36..5101b39 100644 --- a/gprofng/src/Makefile.in +++ b/gprofng/src/Makefile.in @@ -540,7 +540,6 @@ AM_CPPFLAGS = $(GPROFNG_CPPFLAGS) -DLOCALEDIR=\"@localedir@\" -I.. -I$(srcdir) \ -I../../bfd -I$(srcdir)/../../bfd $(ZLIBINC) AM_CFLAGS = $(GPROFNG_CFLAGS) $(PTHREAD_CFLAGS) \ - $(GPROFNG_NO_FORMAT_TRUNCATION_CFLAGS) \ $(GPROFNG_NO_SWITCH_CFLAGS) AM_CXXFLAGS = $(AM_CFLAGS) diff --git a/gprofng/src/ipc.cc b/gprofng/src/ipc.cc index edc7025..06ba33d 100644 --- a/gprofng/src/ipc.cc +++ b/gprofng/src/ipc.cc @@ -95,11 +95,6 @@ extern "C" /* * Fatal error handlers */ -extern "C" void fatalErrorHadler (int sig, siginfo_t *info, void *context); -extern "C" void sigSEGV_handler (int sig, siginfo_t *info, void *context); -extern "C" void sigABRT_handler (int sig, siginfo_t *info, void *context); -static char fatalErrorBuffer1[1024 * 8]; -static char fatalErrorBuffer2[1024 * 8]; static int fatalErrorCode = 1; static int fatalErrorCounter = 0; static void *fatalErrorContext = 0; @@ -127,38 +122,24 @@ fatalErrorHadler (int sig, siginfo_t *info, void *context) // Get process ID pid_t pid = getpid (); // Create dump file - snprintf (fatalErrorBuffer1, sizeof (fatalErrorBuffer1), "/tmp/analyzer.%lld", - (long long) pid); - mkdir (fatalErrorBuffer1, 0700); - snprintf (fatalErrorBuffer1, sizeof (fatalErrorBuffer1), - "/tmp/analyzer.%lld/crash.sig%d.%lld", (long long) pid, sig, - (long long) pid); + char fname[128]; + snprintf (fname, sizeof (fname), "/tmp/gprofng.%lld", (long long) pid); + mkdir (fname, 0700); + snprintf (fname, sizeof (fname), "/tmp/gprofng.%lld/crash.sig%d.%lld", + (long long) pid, sig, (long long) pid); // Dump stack trace in background using pstack - snprintf (fatalErrorBuffer2, sizeof (fatalErrorBuffer2), - "/usr/bin/pstack %lld > %s.pstack", (long long) pid, fatalErrorBuffer1); - system (fatalErrorBuffer2); - int fd = creat (fatalErrorBuffer1, 0600); + char buf[256]; + snprintf (buf, sizeof (buf), "/usr/bin/pstack %lld > %s.pstack", + (long long) pid, fname); + system (buf); + int fd = creat (fname, 0600); if (fd >= 0) { // Write error message - snprintf (fatalErrorBuffer2, sizeof (fatalErrorBuffer2), - "A fatal error has been detected by er_print: Signal %lld\n", - (long long) sig); - write (fd, fatalErrorBuffer2, strlen (fatalErrorBuffer2)); -// snprintf (fatalErrorBuffer2, sizeof (fatalErrorBuffer2), -// "If you would like to submit a bug report, please use your support contract.\n")); -// write(fd, fatalErrorBuffer2, strlen(fatalErrorBuffer2)); - snprintf (fatalErrorBuffer2, sizeof (fatalErrorBuffer2), - "Protocol Version: %d\n", IPC_VERSION_NUMBER); - write (fd, fatalErrorBuffer2, strlen (fatalErrorBuffer2)); + dbe_write (fd, "A fatal error has been detected by er_print: Signal %d\n", + sig); + dbe_write (fd, "Protocol Version: %d\n", IPC_VERSION_NUMBER); close (fd); - // Send postmortem error message to the GUI - // snprintf(fatalErrorBuffer1, sizeof (fatalErrorBuffer1), - // "%s: %s: /tmp/analyzer.%lld", - // "Unexpected signal in er_print", - // "Crash dump", - // (long long) pid); - // res = write(2, fatalErrorBuffer2, strlen(fatalErrorBuffer1)); } wait (0); // wait for pstack //sleep(10); // Wait 10 seconds to make sure processing of fatal error is done diff --git a/gprofng/src/parse.cc b/gprofng/src/parse.cc index eaed8ee..cdbe0ce 100644 --- a/gprofng/src/parse.cc +++ b/gprofng/src/parse.cc @@ -33,6 +33,7 @@ #include "PRBTree.h" #include "Sample.h" #include "Elf.h" +#include "StringBuilder.h" void Experiment::mrec_insert (MapRecord *mrec) @@ -883,10 +884,12 @@ Experiment::process_Linux_kernel_cmd (hrtime_t ts) if (sym_text) { - char fname[128]; - snprintf (fname, sizeof (fname), "%s`%s", mod_name, sym_name); + StringBuilder sb; + sb.appendf ("%s`%s", mod_name, sym_name); + char *fname = sb.toString (); Function *func = dbeSession->createFunction (); func->set_name (fname); + free (fname); func->size = sym_size; func->img_offset = sym_addr; func->module = mod; -- cgit v1.1