Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: runtime/vm/debuginfo.h

Issue 9139080: Rename the VM internal class ByteArray to ByteVector. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: new strategy Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/debuginfo_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef VM_DEBUGINFO_H_ 5 #ifndef VM_DEBUGINFO_H_
6 #define VM_DEBUGINFO_H_ 6 #define VM_DEBUGINFO_H_
7 7
8 #include "vm/assert.h" 8 #include "vm/assert.h"
9 #include "vm/globals.h" 9 #include "vm/globals.h"
10 #include "vm/utils.h" 10 #include "vm/utils.h"
11 11
12 namespace dart { 12 namespace dart {
13 13
14 // A basic ByteArray which is growable and uses malloc/free.
15 class ByteArray {
16 public:
17 ByteArray() : size_(0), capacity_(0), data_(NULL) { }
18 ~ByteArray() {
19 free(data_);
20 size_ = 0;
21 capacity_ = 0;
22 data_ = NULL;
23 }
24
25 uint8_t at(int index) const {
26 ASSERT(0 <= index);
27 ASSERT(index < size_);
28 ASSERT(size_ <= capacity_);
29 return data_[index];
30 }
31
32 uint8_t* data() const { return data_; }
33 void set_data(uint8_t* value) { data_ = value; }
34 int size() const { return size_; }
35
36 // Append an element.
37 void Add(const uint8_t value) {
38 Resize(size() + 1);
39 data_[size() - 1] = value;
40 }
41
42 private:
43 void Resize(int new_size) {
44 if (new_size > capacity_) {
45 int new_capacity = Utils::RoundUpToPowerOfTwo(new_size);
46 uint8_t* new_data =
47 reinterpret_cast<uint8_t*>(realloc(data_, new_capacity));
48 ASSERT(new_data != NULL);
49 data_ = new_data;
50 capacity_ = new_capacity;
51 }
52 size_ = new_size;
53 }
54
55 int size_;
56 int capacity_;
57 uint8_t* data_;
58
59 // Disallow assignment
60 DISALLOW_COPY_AND_ASSIGN(ByteArray);
61 };
62
63
64 // DebugInfo is used to generate minimal debug information containing code, 14 // DebugInfo is used to generate minimal debug information containing code,
65 // symbols, and line numbers for generated code in the dart VM. This information 15 // symbols, and line numbers for generated code in the dart VM. This information
66 // can be used in two ways: 16 // can be used in two ways:
67 // - for debugging using a debugger 17 // - for debugging using a debugger
68 // - for generating information to be read by pprof to analyze Dart programs. 18 // - for generating information to be read by pprof to analyze Dart programs.
69 class DebugInfo { 19 class DebugInfo {
70 public: 20 public:
21 // A basic ByteBuffer which is growable and uses malloc/free.
22 class ByteBuffer {
23 public:
24 ByteBuffer() : size_(0), capacity_(0), data_(NULL) { }
25 ~ByteBuffer() {
26 free(data_);
27 size_ = 0;
28 capacity_ = 0;
29 data_ = NULL;
30 }
31
32 uint8_t at(int index) const {
33 ASSERT(0 <= index);
34 ASSERT(index < size_);
35 ASSERT(size_ <= capacity_);
36 return data_[index];
37 }
38
39 uint8_t* data() const { return data_; }
40 void set_data(uint8_t* value) { data_ = value; }
41 int size() const { return size_; }
42
43 // Append an element.
44 void Add(const uint8_t value) {
45 Resize(size() + 1);
46 data_[size() - 1] = value;
47 }
48
49 private:
50 void Resize(int new_size) {
51 if (new_size > capacity_) {
52 int new_capacity = Utils::RoundUpToPowerOfTwo(new_size);
53 uint8_t* new_data =
54 reinterpret_cast<uint8_t*>(realloc(data_, new_capacity));
55 ASSERT(new_data != NULL);
56 data_ = new_data;
57 capacity_ = new_capacity;
58 }
59 size_ = new_size;
60 }
61
62 int size_;
63 int capacity_;
64 uint8_t* data_;
65
66 // Disallow assignment
67 DISALLOW_COPY_AND_ASSIGN(ByteBuffer);
68 };
69
71 ~DebugInfo(); 70 ~DebugInfo();
72 71
73 // Add the code starting at pc. 72 // Add the code starting at pc.
74 void AddCode(uword pc, intptr_t size); 73 void AddCode(uword pc, intptr_t size);
75 74
76 // Add symbol information for a region (includes the start and end symbol), 75 // Add symbol information for a region (includes the start and end symbol),
77 // does not add the actual code. 76 // does not add the actual code.
78 void AddCodeRegion(const char* name, uword pc, intptr_t size); 77 void AddCodeRegion(const char* name, uword pc, intptr_t size);
79 78
80 // Write out all the debug information info the memory region. 79 // Write out all the debug information info the memory region.
81 bool WriteToMemory(ByteArray* region); 80 bool WriteToMemory(ByteBuffer* region);
82 81
83 // Create a new debug information generator. 82 // Create a new debug information generator.
84 static DebugInfo* NewGenerator(); 83 static DebugInfo* NewGenerator();
85 84
86 // Register this generated section with debuggger using the JIT interface. 85 // Register this generated section with debuggger using the JIT interface.
87 static void RegisterSection(const char* name, 86 static void RegisterSection(const char* name,
88 uword entry_point, 87 uword entry_point,
89 intptr_t size); 88 intptr_t size);
90 89
91 // Unregister all generated section from debuggger. 90 // Unregister all generated section from debuggger.
92 static void UnregisterAllSections(); 91 static void UnregisterAllSections();
93 92
94 private: 93 private:
95 void* handle_; 94 void* handle_;
96 DebugInfo(); 95 DebugInfo();
97 96
98 DISALLOW_COPY_AND_ASSIGN(DebugInfo); 97 DISALLOW_COPY_AND_ASSIGN(DebugInfo);
99 }; 98 };
100 99
101 } // namespace dart 100 } // namespace dart
102 101
103 #endif // VM_DEBUGINFO_H_ 102 #endif // VM_DEBUGINFO_H_
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/debuginfo_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698