Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] OOPify/C++ify ObjectInformation
[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 dw_frame_t ObjectInformation::find_function(const void *ip) const
18 {
19   xbt_dynar_t dynar = this->functions_index;
20   mc_function_index_item_t base =
21       (mc_function_index_item_t) xbt_dynar_get_ptr(dynar, 0);
22   int i = 0;
23   int j = xbt_dynar_length(dynar) - 1;
24   while (j >= i) {
25     int k = i + ((j - i) / 2);
26     if (ip < base[k].low_pc) {
27       j = k - 1;
28     } else if (ip >= base[k].high_pc) {
29       i = k + 1;
30     } else {
31       return base[k].function;
32     }
33   }
34   return nullptr;
35 }
36
37 dw_variable_t ObjectInformation::find_variable(const char* name) const
38 {
39   unsigned int cursor = 0;
40   dw_variable_t variable;
41   xbt_dynar_foreach(this->global_variables, cursor, variable){
42     if(!strcmp(name, variable->name))
43       return variable;
44   }
45
46   return nullptr;
47 }
48
49 }
50 }