Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] OOPify/C++ify Type
[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 // Type
18
19 Type::Type()
20 {
21   this->type = 0;
22   this->id = 0;
23   this->name = std::string();
24   this->byte_size = 0;
25   this->element_count = 0;
26   this->members = nullptr;
27   this->is_pointer_type = 0;
28   this->location = {0, 0, 0, 0};
29   this->offset = 0;
30   this->subtype = nullptr;
31   this->full_type = nullptr;
32 }
33
34 Type::~Type()
35 {
36   xbt_dynar_free(&this->members);
37   mc_dwarf_expression_clear(&this->location);
38 }
39
40 // ObjectInformations
41
42 dw_frame_t ObjectInformation::find_function(const void *ip) const
43 {
44   xbt_dynar_t dynar = this->functions_index;
45   mc_function_index_item_t base =
46       (mc_function_index_item_t) xbt_dynar_get_ptr(dynar, 0);
47   int i = 0;
48   int j = xbt_dynar_length(dynar) - 1;
49   while (j >= i) {
50     int k = i + ((j - i) / 2);
51     if (ip < base[k].low_pc) {
52       j = k - 1;
53     } else if (ip >= base[k].high_pc) {
54       i = k + 1;
55     } else {
56       return base[k].function;
57     }
58   }
59   return nullptr;
60 }
61
62 dw_variable_t ObjectInformation::find_variable(const char* name) const
63 {
64   unsigned int cursor = 0;
65   dw_variable_t variable;
66   xbt_dynar_foreach(this->global_variables, cursor, variable){
67     if(!strcmp(name, variable->name))
68       return variable;
69   }
70
71   return nullptr;
72 }
73
74 }
75 }