| OLD | NEW |
| 1 // Copyright (c) 2009, Google Inc. | 1 // Copyright (c) 2009, Google Inc. |
| 2 // All rights reserved. | 2 // All rights reserved. |
| 3 // | 3 // |
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
| 6 // met: | 6 // met: |
| 7 // | 7 // |
| 8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
| 9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
| 10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | 29 |
| 30 // --- | 30 // --- |
| 31 // Author: Craig Silverstein | 31 // Author: Craig Silverstein |
| 32 | 32 |
| 33 #ifndef TCMALLOC_SYMBOLIZE_H_ | 33 #ifndef TCMALLOC_SYMBOLIZE_H_ |
| 34 #define TCMALLOC_SYMBOLIZE_H_ | 34 #define TCMALLOC_SYMBOLIZE_H_ |
| 35 | 35 |
| 36 #include "config.h" |
| 37 #ifdef HAVE_STDINT_H |
| 38 #include <stdint.h> // for uintptr_t |
| 39 #endif |
| 36 #include <map> | 40 #include <map> |
| 37 | 41 |
| 38 using std::map; | 42 using std::map; |
| 39 | 43 |
| 40 // An average size of memory allocated for a stack trace symbol. | 44 // SymbolTable encapsulates the address operations necessary for stack trace |
| 41 static const int kSymbolSize = 1024; | 45 // symbolization. A common use-case is to Add() the addresses from one or |
| 46 // several stack traces to a table, call Symbolize() once and use GetSymbol() |
| 47 // to get the symbol names for pretty-printing the stack traces. |
| 48 class SymbolTable { |
| 49 public: |
| 50 SymbolTable() |
| 51 : symbol_buffer_(NULL) {} |
| 52 ~SymbolTable() { |
| 53 delete[] symbol_buffer_; |
| 54 } |
| 42 | 55 |
| 43 // TODO(glider): it's better to make SymbolMap a class that encapsulates the | 56 // Adds an address to the table. This may overwrite a currently known symbol |
| 44 // address operations and has the Symbolize() method. | 57 // name, so Add() should not generally be called after Symbolize(). |
| 45 typedef map<uintptr_t, char*> SymbolMap; | 58 void Add(const void* addr); |
| 46 | 59 |
| 47 extern bool Symbolize(char *out, int out_size, | 60 // Returns the symbol name for addr, if the given address was added before |
| 48 SymbolMap *symbolization_table); | 61 // the last successful call to Symbolize(). Otherwise may return an empty |
| 62 // c-string. |
| 63 const char* GetSymbol(const void* addr); |
| 64 |
| 65 // Obtains the symbol names for the addresses stored in the table and returns |
| 66 // the number of addresses actually symbolized. |
| 67 int Symbolize(); |
| 68 |
| 69 private: |
| 70 typedef map<const void*, const char*> SymbolMap; |
| 71 |
| 72 // An average size of memory allocated for a stack trace symbol. |
| 73 static const int kSymbolSize = 1024; |
| 74 |
| 75 // Map from addresses to symbol names. |
| 76 SymbolMap symbolization_table_; |
| 77 |
| 78 // Pointer to the buffer that stores the symbol names. |
| 79 char *symbol_buffer_; |
| 80 }; |
| 49 | 81 |
| 50 #endif // TCMALLOC_SYMBOLIZE_H_ | 82 #endif // TCMALLOC_SYMBOLIZE_H_ |
| OLD | NEW |