Skip to content

Commit

Permalink
Fix some namespace issues for ADL
Browse files Browse the repository at this point in the history
  • Loading branch information
peadar committed Dec 18, 2024
1 parent 0c83082 commit 3eea801
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 17 deletions.
4 changes: 3 additions & 1 deletion dump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -994,3 +994,5 @@ operator <<(std::ostream &os, const JSON<prpsinfo_t> &jo)
.field("pr_args", args )
;
}
}

18 changes: 12 additions & 6 deletions libpstack/dwarf.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ class CFI;
struct CIE;
}

namespace pstack {

std::ostream & operator << (std::ostream &os, const JSON<pstack::Dwarf::CFI> &);

namespace pstack::Dwarf {
namespace Dwarf {

#define DWARF_TAG(a,b) a = (b),
enum Tag {
Expand Down Expand Up @@ -60,14 +62,17 @@ enum AttrName {
DW_AT_none = 0x0
};

}
} // Dwarf

} // pstack
namespace std {
template <> struct hash<pstack::Dwarf::AttrName> {
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 {
Expand Down Expand Up @@ -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<pstack::Dwarf::Info> &);
std::ostream &operator << (std::ostream &os, const JSON<pstack::Dwarf::Macros> &);
std::ostream &operator << (std::ostream &os, const JSON<pstack::Dwarf::DIE> &);
std::ostream &operator << (std::ostream &os, const JSON<Dwarf::Info> &);
std::ostream &operator << (std::ostream &os, const JSON<Dwarf::Macros> &);
std::ostream &operator << (std::ostream &os, const JSON<Dwarf::DIE> &);
}

#endif
4 changes: 3 additions & 1 deletion libpstack/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ class SymbolSection;
class NoteDesc;
};

namespace pstack {
std::ostream &operator<< (std::ostream &, const JSON<pstack::Elf::Object> &);
}

namespace pstack::Elf {

Expand Down Expand Up @@ -339,7 +341,7 @@ class Object : public std::enable_shared_from_this<Object> {
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<Object> &);
friend std::ostream &pstack::operator<< (std::ostream &, const pstack::JSON<Object> &);

// used to cache the debug symbol table by name. Popualted first time something requests such a symbol
std::unique_ptr<std::map<std::string, size_t>> cachedSymbols;
Expand Down
2 changes: 2 additions & 0 deletions libpstack/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <cstdlib>
#include <iomanip>

namespace pstack {
/*
* General purpose way of printing out JSON objects.
* Given an std::ostream &s, we can do:
Expand Down Expand Up @@ -312,6 +313,7 @@ std::ostream &
operator << (std::ostream &os, const JSON<JsonNull, C> &) {
return os << "null";
}
}


#endif
8 changes: 6 additions & 2 deletions libpstack/proc.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ extern "C" {

struct ps_prochandle {};

namespace pstack::Procman {
namespace pstack {
namespace Procman {

class Process;

Expand Down Expand Up @@ -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<pstack::Procman::StackFrame, pstack::Procman::Process *> &jt);
std::ostream &operator << (std::ostream &os, const JSON<pstack::Procman::ThreadStack, pstack::Procman::Process *> &jt);
std::ostream &operator << (std::ostream &os, const JSON<pstack::Procman::FileEntry> &);

}

std::ostream &operator << (std::ostream &os, const siginfo_t &);

#endif
14 changes: 9 additions & 5 deletions process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::pair<std::string, int>> &jt)
Expand Down Expand Up @@ -72,14 +72,16 @@ operator << (std::ostream &os, const JSON<Procman::ThreadStack, Procman::Process
.field("ti_stack", ts.object.stack, ts.context);
}

}

namespace std {
bool
operator < (const std::pair<Elf::Addr, Elf::Object::sptr> &entry, Elf::Addr addr) {
operator < (const std::pair<pstack::Elf::Addr, pstack::Elf::Object::sptr> &entry, pstack::Elf::Addr addr) {
return entry.first < addr;
}
}

namespace pstack {
template <typename ctx>
std::ostream &
operator << (std::ostream &os, const JSON<td_thr_type_e, ctx> &jt)
Expand All @@ -92,7 +94,7 @@ operator << (std::ostream &os, const JSON<td_thr_type_e, ctx> &jt)
}
}

namespace pstack::Procman {
namespace Procman {

/*
* convert a gregset_t to an Elf::CoreRegs
Expand Down Expand Up @@ -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))
Expand All @@ -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<Procman::StackFrame, Procman::Process *> &jt)
Expand Down Expand Up @@ -1158,6 +1160,8 @@ operator << (std::ostream &os, const JSON<Procman::StackFrame, Procman::Process
return jo;
}

}

std::ostream &operator << (std::ostream &os, const siginfo_t &si) {

static std::map<int, std::map<int, const char *>> codes {
Expand Down
1 change: 0 additions & 1 deletion python3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <unicodeobject.h>
#include <methodobject.h>
#include "libpstack/python.h"
#include "libpstack/global.h"
#include "libpstack/fs.h"

#define DK_SIZE(dk) ((dk)->dk_size)
Expand Down
2 changes: 1 addition & 1 deletion tests/thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3eea801

Please sign in to comment.