Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiud committed Oct 31, 2024
1 parent 644f0e9 commit 93922d5
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 32 deletions.
7 changes: 4 additions & 3 deletions src/demangle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1352,10 +1352,11 @@ bool Demangle(const char* mangled, char* out, size_t out_size) {

if (out_size > 0) {
// n is the size of the allocated buffer, not the length of the string.
// Therefore, it includes the terminating zero (and possibly additional space).
std::size_t copy_size = std::min(n-1, out_size - 1);
// Therefore, it includes the terminating zero (and possibly additional
// space).
std::size_t copy_size = std::min(n - 1, out_size - 1);
std::copy_n(unmangled.get(), copy_size, out);
out[copy_size] = '\0'; // Ensure terminating null if n > out_size
out[copy_size] = '\0'; // Ensure terminating null if n > out_size
}
return status == 0;
#else
Expand Down
95 changes: 66 additions & 29 deletions src/symbolize_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@
#include <map>
#include <string>


#include "config.h"
#include "glog/logging.h"
#include "googletest.h"
#include "utilities.h"
#include "stacktrace.h"
#include "utilities.h"

#ifdef GLOG_USE_GFLAGS
# include <gflags/gflags.h>
Expand Down Expand Up @@ -137,18 +136,36 @@ TEST(Symbolize, Symbolize) {

struct Foo {
static void func(int x);
static size_t longParamFunc(
std::map<std::map<std::string, std::string>,std::map<std::string, std::string> > p0,
std::map<std::map<std::string, std::string>,std::map<std::string, std::string> > p1,
std::map<std::map<std::string, std::string>,std::map<std::string, std::string> > p2,
std::map<std::map<std::string, std::string>,std::map<std::string, std::string> > p3,
std::map<std::map<std::string, std::string>,std::map<std::string, std::string> > p4,
std::map<std::map<std::string, std::string>,std::map<std::string, std::string> > p5,
std::map<std::map<std::string, std::string>,std::map<std::string, std::string> > p6,
std::map<std::map<std::string, std::string>,std::map<std::string, std::string> > p7,
std::map<std::map<std::string, std::string>,std::map<std::string, std::string> > p8,
std::map<std::map<std::string, std::string>,std::map<std::string, std::string> > p9
);
static size_t longParamFunc(std::map<std::map<std::string, std::string>,
std::map<std::string, std::string>>
p0,
std::map<std::map<std::string, std::string>,
std::map<std::string, std::string>>
p1,
std::map<std::map<std::string, std::string>,
std::map<std::string, std::string>>
p2,
std::map<std::map<std::string, std::string>,
std::map<std::string, std::string>>
p3,
std::map<std::map<std::string, std::string>,
std::map<std::string, std::string>>
p4,
std::map<std::map<std::string, std::string>,
std::map<std::string, std::string>>
p5,
std::map<std::map<std::string, std::string>,
std::map<std::string, std::string>>
p6,
std::map<std::map<std::string, std::string>,
std::map<std::string, std::string>>
p7,
std::map<std::map<std::string, std::string>,
std::map<std::string, std::string>>
p8,
std::map<std::map<std::string, std::string>,
std::map<std::string, std::string>>
p9);
};

void ATTRIBUTE_NOINLINE Foo::func(int x) {
Expand All @@ -158,19 +175,39 @@ void ATTRIBUTE_NOINLINE Foo::func(int x) {
a = a + 1;
}

size_t ATTRIBUTE_NOINLINE Foo::longParamFunc(
std::map<std::map<std::string, std::string>,std::map<std::string, std::string> > p0,
std::map<std::map<std::string, std::string>,std::map<std::string, std::string> > p1,
std::map<std::map<std::string, std::string>,std::map<std::string, std::string> > p2,
std::map<std::map<std::string, std::string>,std::map<std::string, std::string> > p3,
std::map<std::map<std::string, std::string>,std::map<std::string, std::string> > p4,
std::map<std::map<std::string, std::string>,std::map<std::string, std::string> > p5,
std::map<std::map<std::string, std::string>,std::map<std::string, std::string> > p6,
std::map<std::map<std::string, std::string>,std::map<std::string, std::string> > p7,
std::map<std::map<std::string, std::string>,std::map<std::string, std::string> > p8,
std::map<std::map<std::string, std::string>,std::map<std::string, std::string> > p9
) {
return p0.size() + p1.size() + p2.size() + p3.size() + p4.size() + p5.size() + p6.size() + p7.size() + p8.size() + p9.size();
size_t ATTRIBUTE_NOINLINE
Foo::longParamFunc(std::map<std::map<std::string, std::string>,
std::map<std::string, std::string>>
p0,
std::map<std::map<std::string, std::string>,
std::map<std::string, std::string>>
p1,
std::map<std::map<std::string, std::string>,
std::map<std::string, std::string>>
p2,
std::map<std::map<std::string, std::string>,
std::map<std::string, std::string>>
p3,
std::map<std::map<std::string, std::string>,
std::map<std::string, std::string>>
p4,
std::map<std::map<std::string, std::string>,
std::map<std::string, std::string>>
p5,
std::map<std::map<std::string, std::string>,
std::map<std::string, std::string>>
p6,
std::map<std::map<std::string, std::string>,
std::map<std::string, std::string>>
p7,
std::map<std::map<std::string, std::string>,
std::map<std::string, std::string>>
p8,
std::map<std::map<std::string, std::string>,
std::map<std::string, std::string>>
p9) {
return p0.size() + p1.size() + p2.size() + p3.size() + p4.size() + p5.size() +
p6.size() + p7.size() + p8.size() + p9.size();
}

// With a modern GCC, Symbolize() should return demangled symbol
Expand All @@ -181,8 +218,8 @@ TEST(Symbolize, SymbolizeWithDemangling) {
# if !defined(_MSC_VER) || !defined(NDEBUG)
# if defined(HAVE___CXA_DEMANGLE)
EXPECT_STREQ("Foo::func(int)", TrySymbolize((void*)(&Foo::func)));
// Very long functions can be truncated, but we should not crash or return null.
// Also the result should start properly.
// Very long functions can be truncated, but we should not crash or return
// null. Also the result should start properly.
const char* symbol = TrySymbolize((void*)(&Foo::longParamFunc));
EXPECT_TRUE(symbol == std::strstr(symbol, "Foo::longParamFunc("));
# else
Expand Down

0 comments on commit 93922d5

Please sign in to comment.