AsmGrader 0.0.0
Loading...
Searching...
No Matches
symbol.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <fmt/base.h>
4#include <fmt/format.h>
5
6#include <cctype>
7#include <cstddef>
8#include <string>
9
10namespace asmgrader {
11
13struct Symbol
14{
15 std::string name;
16
18 enum { Static, Dynamic } kind;
19
20 std::size_t address;
21
23};
24
25} // namespace asmgrader
26
27template <>
28struct fmt::formatter<::asmgrader::Symbol> : formatter<std::string>
29{
30 template <typename Context>
31 auto format(const ::asmgrader::Symbol& from, Context& ctx) const {
32 using Symbol = ::asmgrader::Symbol;
33
34 const std::string kind_str = [&from]() {
35 switch (from.kind) {
36 case Symbol::Static:
37 return "Static";
38 case Symbol::Dynamic:
39 return "Dynamic";
40 default:
41 return "<unknown>";
42 }
43 }();
44 const std::string binding_str = [&from]() {
45 switch (from.binding) {
46 case Symbol::Local:
47 return "Local";
48 case Symbol::Global:
49 return "Global";
50 case Symbol::Weak:
51 return "Weak";
52 case Symbol::Other:
53 return "Other";
54 default:
55 return "<unknown>";
56 }
57 }();
58
59 return fmt::format_to(ctx.out(), "Symbol{{.name={:?}, .kind={}, .address=0x{:X}, .binding={}}}", from.name,
60 kind_str, from.address, binding_str);
61 }
62};
Definition asm_buffer.hpp:19
Basic definition for a symbol found in an ELF file.
Definition symbol.hpp:14
@ Global
Definition symbol.hpp:22
@ Other
Definition symbol.hpp:22
@ Local
Definition symbol.hpp:22
@ Weak
Definition symbol.hpp:22
@ Static
Definition symbol.hpp:18
@ Dynamic
Definition symbol.hpp:18
std::size_t address
Definition symbol.hpp:20
enum asmgrader::Symbol::@3 binding
enum asmgrader::Symbol::@2 kind
I.e.: found in .symtab or .dynsym respectively.
std::string name
Definition symbol.hpp:15
auto format(const ::asmgrader::Symbol &from, Context &ctx) const
Definition symbol.hpp:31