Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] C++ location lists and expressions
[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->address = nullptr;
51   this->start_scope = 0;
52   this->object_info = nullptr;
53 }
54
55 // Frame
56
57 Frame::Frame()
58 {
59   this->tag = 0;
60   this->low_pc = nullptr;
61   this->high_pc = nullptr;
62   this->variables = xbt_dynar_new(
63     sizeof(mc_variable_t), mc_variable_free_voidp);
64   this->id = 0;
65   this->scopes = xbt_dynar_new(
66     sizeof(mc_frame_t), (void_f_pvoid_t) mc_frame_free_voipd);
67   this->abstract_origin_id = 0;
68   this->object_info = nullptr;
69 }
70
71 Frame::~Frame()
72 {
73   xbt_dynar_free(&(this->variables));
74   xbt_dynar_free(&(this->scopes));
75 }
76
77 // ObjectInformations
78
79 mc_frame_t ObjectInformation::find_function(const void *ip) const
80 {
81   xbt_dynar_t dynar = this->functions_index;
82   mc_function_index_item_t base =
83       (mc_function_index_item_t) xbt_dynar_get_ptr(dynar, 0);
84   int i = 0;
85   int j = xbt_dynar_length(dynar) - 1;
86   while (j >= i) {
87     int k = i + ((j - i) / 2);
88     if (ip < base[k].low_pc) {
89       j = k - 1;
90     } else if (ip >= base[k].high_pc) {
91       i = k + 1;
92     } else {
93       return base[k].function;
94     }
95   }
96   return nullptr;
97 }
98
99 mc_variable_t ObjectInformation::find_variable(const char* name) const
100 {
101   unsigned int cursor = 0;
102   mc_variable_t variable;
103   xbt_dynar_foreach(this->global_variables, cursor, variable)
104     if(variable->name == name)
105       return variable;
106   return nullptr;
107 }
108
109 }
110 }