libcsdbg  1.28
C++ exception (and generic) stack trace debug library
symbol.cpp
Go to the documentation of this file.
1 #include "../include/symbol.hpp"
2 
9 namespace csdbg {
10 
20 symbol::symbol(mem_addr_t addr, const i8 *nm):
21 m_addr(addr),
22 m_name(NULL)
23 {
24  __D_ASSERT(nm != NULL);
25  if ( likely(nm != NULL) ) {
26  m_name = new i8[strlen(nm) + 1];
27  strcpy(m_name, nm);
28  }
29 }
30 
31 
39 symbol::symbol(const symbol &src):
40 m_addr(src.m_addr),
41 m_name(NULL)
42 {
43  i8 *buf = src.m_name;
44  if ( likely(buf != NULL) ) {
45  m_name = new i8[strlen(buf) + 1];
46  strcpy(m_name, buf);
47  }
48 }
49 
50 
55 {
56  delete[] m_name;
57  m_name = NULL;
58 }
59 
60 
68 inline symbol* symbol::clone() const
69 {
70  return new symbol(*this);
71 }
72 
73 
79 inline mem_addr_t symbol::addr() const
80 {
81  return m_addr;
82 }
83 
84 
90 inline const i8* symbol::name() const
91 {
92  return m_name;
93 }
94 
95 
106 {
107  if ( unlikely(this == &rval) )
108  return *this;
109 
110  m_addr = rval.m_addr;
111 
112  i8 *buf = rval.m_name;
113  if ( unlikely(buf == NULL) ) {
114  delete[] m_name;
115  m_name = NULL;
116  return *this;
117  }
118 
119  u32 len = strlen(buf);
120  if ( unlikely(m_name == NULL || len > strlen(m_name)) ) {
121  delete[] m_name;
122  m_name = NULL;
123  m_name = new i8[len + 1];
124  }
125 
126  strcpy(m_name, buf);
127  return *this;
128 }
129 
130 }
131 
virtual symbol & operator=(const symbol &)
Assignment operator.
Definition: symbol.cpp:105
This class represents a program/library function symbol.
Definition: symbol.hpp:17
virtual symbol * clone() const
Object virtual copy constructor.
Definition: symbol.cpp:68
virtual ~symbol()
Object destructor.
Definition: symbol.cpp:54
char i8
8-bit signed integer
Definition: config.hpp:72
mem_addr_t m_addr
Symbol address.
Definition: symbol.hpp:23
#define likely(expr)
Offer a hint (positive) to the pipeline branch predictor.
Definition: config.hpp:344
virtual mem_addr_t addr() const
Get the symbol address.
Definition: symbol.cpp:79
virtual const i8 * name() const
Get the symbol name.
Definition: symbol.cpp:90
unsigned int u32
32-bit unsigned integer
Definition: config.hpp:102
symbol(mem_addr_t, const i8 *)
Object constructor.
Definition: symbol.cpp:20
i8 * m_name
Symbol name.
Definition: symbol.hpp:25
unsigned long long mem_addr_t
64-bit memory address
Definition: config.hpp:120
#define unlikely(expr)
Offer a hint (negative) to the pipeline branch predictor.
Definition: config.hpp:349
#define __D_ASSERT(x)
Assertion macro.
Definition: config.hpp:268