From 3eea80122ad529d1e565732dcc381ca6120e5dc9 Mon Sep 17 00:00:00 2001 From: Peter Edwards Date: Wed, 18 Dec 2024 16:33:04 +0000 Subject: [PATCH] Fix some namespace issues for ADL --- dump.cc | 4 +++- libpstack/dwarf.h | 18 ++++++++++++------ libpstack/elf.h | 4 +++- libpstack/json.h | 2 ++ libpstack/proc.h | 8 ++++++-- process.cc | 14 +++++++++----- python3.cc | 1 - tests/thread.cc | 2 +- 8 files changed, 36 insertions(+), 17 deletions(-) diff --git a/dump.cc b/dump.cc index 704cf63..2c4babe 100644 --- a/dump.cc +++ b/dump.cc @@ -16,7 +16,7 @@ #error "Non-32, non-64-bit platform?" #endif -using namespace pstack; +namespace pstack { struct DumpCFAInsns { Elf::Off start; Elf::Off end; @@ -994,3 +994,5 @@ operator <<(std::ostream &os, const JSON &jo) .field("pr_args", args ) ; } +} + diff --git a/libpstack/dwarf.h b/libpstack/dwarf.h index 69fac91..a8763a2 100644 --- a/libpstack/dwarf.h +++ b/libpstack/dwarf.h @@ -22,9 +22,11 @@ class CFI; struct CIE; } +namespace pstack { + std::ostream & operator << (std::ostream &os, const JSON &); -namespace pstack::Dwarf { +namespace Dwarf { #define DWARF_TAG(a,b) a = (b), enum Tag { @@ -60,14 +62,17 @@ enum AttrName { DW_AT_none = 0x0 }; -} +} // Dwarf + +} // pstack namespace std { template <> struct hash { size_t operator() (pstack::Dwarf::AttrName name) const { return size_t(name); } }; } -namespace pstack::Dwarf { +namespace pstack { +namespace Dwarf { #define DWARF_OP(op, value, args) op = (value), enum ExpressionOp { @@ -836,8 +841,9 @@ Units::iterator::iterator(const Info *info_, Elf::Off offset) : info(info_), currentUnit(info->getUnit(offset)) {} } -std::ostream &operator << (std::ostream &os, const JSON &); -std::ostream &operator << (std::ostream &os, const JSON &); -std::ostream &operator << (std::ostream &os, const JSON &); +std::ostream &operator << (std::ostream &os, const JSON &); +std::ostream &operator << (std::ostream &os, const JSON &); +std::ostream &operator << (std::ostream &os, const JSON &); +} #endif diff --git a/libpstack/elf.h b/libpstack/elf.h index 25e5878..bbfa667 100644 --- a/libpstack/elf.h +++ b/libpstack/elf.h @@ -73,7 +73,9 @@ class SymbolSection; class NoteDesc; }; +namespace pstack { std::ostream &operator<< (std::ostream &, const JSON &); +} namespace pstack::Elf { @@ -339,7 +341,7 @@ class Object : public std::enable_shared_from_this { GnuHash *gnu_hash() { return get_hash(gnu_hash_); } Object *getDebug() const; // Gets linked debug object. Note that getSection indirects through this. - friend std::ostream &::operator<< (std::ostream &, const JSON &); + friend std::ostream &pstack::operator<< (std::ostream &, const pstack::JSON &); // used to cache the debug symbol table by name. Popualted first time something requests such a symbol std::unique_ptr> cachedSymbols; diff --git a/libpstack/json.h b/libpstack/json.h index f073723..2941ead 100644 --- a/libpstack/json.h +++ b/libpstack/json.h @@ -6,6 +6,7 @@ #include #include +namespace pstack { /* * General purpose way of printing out JSON objects. * Given an std::ostream &s, we can do: @@ -312,6 +313,7 @@ std::ostream & operator << (std::ostream &os, const JSON &) { return os << "null"; } +} #endif diff --git a/libpstack/proc.h b/libpstack/proc.h index fb07e75..668d406 100644 --- a/libpstack/proc.h +++ b/libpstack/proc.h @@ -23,7 +23,8 @@ extern "C" { struct ps_prochandle {}; -namespace pstack::Procman { +namespace pstack { +namespace Procman { class Process; @@ -481,12 +482,15 @@ struct WaitStatus { }; void gregset2core(Elf::CoreRegisters &core, const gregset_t greg); +std::ostream &operator << (std::ostream &os, WaitStatus ws); } -std::ostream &operator << (std::ostream &os, pstack::Procman::WaitStatus ws); std::ostream &operator << (std::ostream &os, const JSON &jt); std::ostream &operator << (std::ostream &os, const JSON &jt); std::ostream &operator << (std::ostream &os, const JSON &); + +} + std::ostream &operator << (std::ostream &os, const siginfo_t &); #endif diff --git a/process.cc b/process.cc index c8dfc3e..43e381b 100644 --- a/process.cc +++ b/process.cc @@ -29,7 +29,7 @@ #elif defined(__aarch64__) #define IP(regs) (regs.pc) #endif -using namespace pstack; +namespace pstack {; std::ostream & operator << (std::ostream &os, const JSON> &jt) @@ -72,14 +72,16 @@ operator << (std::ostream &os, const JSON &entry, Elf::Addr addr) { +operator < (const std::pair &entry, pstack::Elf::Addr addr) { return entry.first < addr; } } +namespace pstack { template std::ostream & operator << (std::ostream &os, const JSON &jt) @@ -92,7 +94,7 @@ operator << (std::ostream &os, const JSON &jt) } } -namespace pstack::Procman { +namespace Procman { /* * convert a gregset_t to an Elf::CoreRegs @@ -1115,10 +1117,9 @@ Process::getStacks() { processSuspender.clear(); return threadStacks; } -} std::ostream & -operator << (std::ostream &os, Procman::WaitStatus ws) { +operator << (std::ostream &os, WaitStatus ws) { if (WIFSIGNALED(ws.status)) { os << "signal(" << strsignal(WTERMSIG(ws.status)) << ")"; if (WCOREDUMP(ws.status)) @@ -1130,6 +1131,7 @@ operator << (std::ostream &os, Procman::WaitStatus ws) { os << "exit(" << WEXITSTATUS(ws.status) << ")"; return os; } +} std::ostream & operator << (std::ostream &os, const JSON &jt) @@ -1158,6 +1160,8 @@ operator << (std::ostream &os, const JSON> codes { diff --git a/python3.cc b/python3.cc index 034ce26..e25f54d 100644 --- a/python3.cc +++ b/python3.cc @@ -7,7 +7,6 @@ #include #include #include "libpstack/python.h" -#include "libpstack/global.h" #include "libpstack/fs.h" #define DK_SIZE(dk) ((dk)->dk_size) diff --git a/tests/thread.cc b/tests/thread.cc index cb02b8a..887ff8d 100644 --- a/tests/thread.cc +++ b/tests/thread.cc @@ -60,7 +60,7 @@ main(int /*unused*/, char ** /*unused*/) pthread_mutex_unlock(&l); } { - JObject(std::cout) + pstack::JObject(std::cout) .field("threads", threads) .field("lwps", lwps) .field("assert_at", assertline);