Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] C++ify Frame
[simgrid.git] / src / mc / mc_object_info.cpp
1 /* Copyright (c) 2014-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include <stddef.h>
8
9 #include <xbt/dynar.h>
10
11 #include "mc_object_info.h"
12 #include "mc_private.h"
13
14 namespace simgrid {
15 namespace mc {
16
17 // Free functions
18
19 static void mc_variable_free_voidp(void *t)
20 {
21   delete *(simgrid::mc::Variable**)t;
22 }
23
24 static void mc_frame_free_voipd(void** p)
25 {
26   delete *(mc_frame_t**)p;
27   *p = nullptr;
28 }
29
30 // Type
31
32 Type::Type()
33 {
34   this->type = 0;
35   this->id = 0;
36   this->byte_size = 0;
37   this->element_count = 0;
38   this->is_pointer_type = 0;
39   this->subtype = nullptr;
40   this->full_type = nullptr;
41 }
42
43 // Type
44
45 Variable::Variable()
46 {
47   this->dwarf_offset = 0;
48   this->global = 0;
49   this->type = nullptr;
50   this->location_list = {0, nullptr};
51   this->address = nullptr;
52   this->start_scope = 0;
53   this->object_info = nullptr;
54 }
55
56 Variable::~Variable()
57 {
58   if (this->location_list.locations)
59     mc_dwarf_location_list_clear(&this->location_list);
60 }
61
62 // Frame
63
64 Frame::Frame()
65 {
66   this->tag = 0;
67   this->low_pc = nullptr;
68   this->high_pc = nullptr;
69   this->frame_base = {0, nullptr};
70   this->variables = xbt_dynar_new(
71     sizeof(mc_variable_t), mc_variable_free_voidp);
72   this->id = 0;
73   this->scopes = xbt_dynar_new(
74     sizeof(mc_frame_t), (void_f_pvoid_t) mc_frame_free_voipd);
75   this->abstract_origin_id = 0;
76   this->object_info = nullptr;
77 }
78
79 Frame::~Frame()
80 {
81   mc_dwarf_location_list_clear(&(this->frame_base));
82   xbt_dynar_free(&(this->variables));
83   xbt_dynar_free(&(this->scopes));
84 }
85
86 // ObjectInformations
87
88 mc_frame_t ObjectInformation::find_function(const void *ip) const
89 {
90   xbt_dynar_t dynar = this->functions_index;
91   mc_function_index_item_t base =
92       (mc_function_index_item_t) xbt_dynar_get_ptr(dynar, 0);
93   int i = 0;
94   int j = xbt_dynar_length(dynar) - 1;
95   while (j >= i) {
96     int k = i + ((j - i) / 2);
97     if (ip < base[k].low_pc) {
98       j = k - 1;
99     } else if (ip >= base[k].high_pc) {
100       i = k + 1;
101     } else {
102       return base[k].function;
103     }
104   }
105   return nullptr;
106 }
107
108 mc_variable_t ObjectInformation::find_variable(const char* name) const
109 {
110   unsigned int cursor = 0;
111   mc_variable_t variable;
112   xbt_dynar_foreach(this->global_variables, cursor, variable)
113     if(variable->name == name)
114       return variable;
115   return nullptr;
116 }
117
118 }
119 }