map.c (0337966d121ebebf73a1c346123e8112796e684e) map.c (d80406453ad4a69932dc17a617d5b7bc7ae80b8f)
1#include "symbol.h"
2#include <errno.h>
3#include <inttypes.h>
4#include <limits.h>
5#include <stdlib.h>
6#include <string.h>
7#include <stdio.h>
8#include <unistd.h>
9#include <uapi/linux/mman.h> /* To get things like MAP_HUGETLB even on older libc headers */
10#include "map.h"
11#include "thread.h"
1#include "symbol.h"
2#include <errno.h>
3#include <inttypes.h>
4#include <limits.h>
5#include <stdlib.h>
6#include <string.h>
7#include <stdio.h>
8#include <unistd.h>
9#include <uapi/linux/mman.h> /* To get things like MAP_HUGETLB even on older libc headers */
10#include "map.h"
11#include "thread.h"
12#include "strlist.h"
13#include "vdso.h"
14#include "build-id.h"
15#include "util.h"
16#include "debug.h"
17#include "machine.h"
18#include <linux/string.h>
12#include "vdso.h"
13#include "build-id.h"
14#include "util.h"
15#include "debug.h"
16#include "machine.h"
17#include <linux/string.h>
18#include "srcline.h"
19#include "unwind.h"
20
21static void __maps__insert(struct maps *maps, struct map *map);
22
23const char *map_type__name[MAP__NR_TYPES] = {
24 [MAP__FUNCTION] = "Functions",
25 [MAP__VARIABLE] = "Variables",
26};

--- 109 unchanged lines hidden (view full) ---

136 map->pgoff = pgoff;
137 map->reloc = 0;
138 map->dso = dso__get(dso);
139 map->map_ip = map__map_ip;
140 map->unmap_ip = map__unmap_ip;
141 RB_CLEAR_NODE(&map->rb_node);
142 map->groups = NULL;
143 map->erange_warned = false;
19#include "unwind.h"
20
21static void __maps__insert(struct maps *maps, struct map *map);
22
23const char *map_type__name[MAP__NR_TYPES] = {
24 [MAP__FUNCTION] = "Functions",
25 [MAP__VARIABLE] = "Variables",
26};

--- 109 unchanged lines hidden (view full) ---

136 map->pgoff = pgoff;
137 map->reloc = 0;
138 map->dso = dso__get(dso);
139 map->map_ip = map__map_ip;
140 map->unmap_ip = map__unmap_ip;
141 RB_CLEAR_NODE(&map->rb_node);
142 map->groups = NULL;
143 map->erange_warned = false;
144 atomic_set(&map->refcnt, 1);
144 refcount_set(&map->refcnt, 1);
145}
146
147struct map *map__new(struct machine *machine, u64 start, u64 len,
148 u64 pgoff, u32 pid, u32 d_maj, u32 d_min, u64 ino,
149 u64 ino_gen, u32 prot, u32 flags, char *filename,
150 enum map_type type, struct thread *thread)
151{
152 struct map *map = malloc(sizeof(*map));

--- 97 unchanged lines hidden (view full) ---

250void map__delete(struct map *map)
251{
252 map__exit(map);
253 free(map);
254}
255
256void map__put(struct map *map)
257{
145}
146
147struct map *map__new(struct machine *machine, u64 start, u64 len,
148 u64 pgoff, u32 pid, u32 d_maj, u32 d_min, u64 ino,
149 u64 ino_gen, u32 prot, u32 flags, char *filename,
150 enum map_type type, struct thread *thread)
151{
152 struct map *map = malloc(sizeof(*map));

--- 97 unchanged lines hidden (view full) ---

250void map__delete(struct map *map)
251{
252 map__exit(map);
253 free(map);
254}
255
256void map__put(struct map *map)
257{
258 if (map && atomic_dec_and_test(&map->refcnt))
258 if (map && refcount_dec_and_test(&map->refcnt))
259 map__delete(map);
260}
261
262void map__fixup_start(struct map *map)
263{
264 struct rb_root *symbols = &map->dso->symbols[map->type];
265 struct rb_node *nd = rb_first(symbols);
266 if (nd != NULL) {

--- 53 unchanged lines hidden (view full) ---

320 }
321#endif
322 return -1;
323 }
324
325 return 0;
326}
327
259 map__delete(map);
260}
261
262void map__fixup_start(struct map *map)
263{
264 struct rb_root *symbols = &map->dso->symbols[map->type];
265 struct rb_node *nd = rb_first(symbols);
266 if (nd != NULL) {

--- 53 unchanged lines hidden (view full) ---

320 }
321#endif
322 return -1;
323 }
324
325 return 0;
326}
327
328int __weak arch__compare_symbol_names(const char *namea, const char *nameb)
329{
330 return strcmp(namea, nameb);
331}
332
333struct symbol *map__find_symbol(struct map *map, u64 addr)
334{
335 if (map__load(map) < 0)
336 return NULL;
337
338 return dso__find_symbol(map->dso, map->type, addr);
339}
340

--- 8 unchanged lines hidden (view full) ---

349 return dso__find_symbol_by_name(map->dso, map->type, name);
350}
351
352struct map *map__clone(struct map *from)
353{
354 struct map *map = memdup(from, sizeof(*map));
355
356 if (map != NULL) {
328struct symbol *map__find_symbol(struct map *map, u64 addr)
329{
330 if (map__load(map) < 0)
331 return NULL;
332
333 return dso__find_symbol(map->dso, map->type, addr);
334}
335

--- 8 unchanged lines hidden (view full) ---

344 return dso__find_symbol_by_name(map->dso, map->type, name);
345}
346
347struct map *map__clone(struct map *from)
348{
349 struct map *map = memdup(from, sizeof(*map));
350
351 if (map != NULL) {
357 atomic_set(&map->refcnt, 1);
352 refcount_set(&map->refcnt, 1);
358 RB_CLEAR_NODE(&map->rb_node);
359 dso__get(map->dso);
360 map->groups = NULL;
361 }
362
363 return map;
364}
365

--- 34 unchanged lines hidden (view full) ---

400int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix,
401 FILE *fp)
402{
403 char *srcline;
404 int ret = 0;
405
406 if (map && map->dso) {
407 srcline = get_srcline(map->dso,
353 RB_CLEAR_NODE(&map->rb_node);
354 dso__get(map->dso);
355 map->groups = NULL;
356 }
357
358 return map;
359}
360

--- 34 unchanged lines hidden (view full) ---

395int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix,
396 FILE *fp)
397{
398 char *srcline;
399 int ret = 0;
400
401 if (map && map->dso) {
402 srcline = get_srcline(map->dso,
408 map__rip_2objdump(map, addr), NULL, true);
403 map__rip_2objdump(map, addr), NULL,
404 true, true);
409 if (srcline != SRCLINE_UNKNOWN)
410 ret = fprintf(fp, "%s%s", prefix, srcline);
411 free_srcline(srcline);
412 }
413 return ret;
414}
415
416/**

--- 63 unchanged lines hidden (view full) ---

480
481void map_groups__init(struct map_groups *mg, struct machine *machine)
482{
483 int i;
484 for (i = 0; i < MAP__NR_TYPES; ++i) {
485 maps__init(&mg->maps[i]);
486 }
487 mg->machine = machine;
405 if (srcline != SRCLINE_UNKNOWN)
406 ret = fprintf(fp, "%s%s", prefix, srcline);
407 free_srcline(srcline);
408 }
409 return ret;
410}
411
412/**

--- 63 unchanged lines hidden (view full) ---

476
477void map_groups__init(struct map_groups *mg, struct machine *machine)
478{
479 int i;
480 for (i = 0; i < MAP__NR_TYPES; ++i) {
481 maps__init(&mg->maps[i]);
482 }
483 mg->machine = machine;
488 atomic_set(&mg->refcnt, 1);
484 refcount_set(&mg->refcnt, 1);
489}
490
491static void __maps__purge(struct maps *maps)
492{
493 struct rb_root *root = &maps->entries;
494 struct rb_node *next = rb_first(root);
495
496 while (next) {

--- 45 unchanged lines hidden (view full) ---

542void map_groups__delete(struct map_groups *mg)
543{
544 map_groups__exit(mg);
545 free(mg);
546}
547
548void map_groups__put(struct map_groups *mg)
549{
485}
486
487static void __maps__purge(struct maps *maps)
488{
489 struct rb_root *root = &maps->entries;
490 struct rb_node *next = rb_first(root);
491
492 while (next) {

--- 45 unchanged lines hidden (view full) ---

538void map_groups__delete(struct map_groups *mg)
539{
540 map_groups__exit(mg);
541 free(mg);
542}
543
544void map_groups__put(struct map_groups *mg)
545{
550 if (mg && atomic_dec_and_test(&mg->refcnt))
546 if (mg && refcount_dec_and_test(&mg->refcnt))
551 map_groups__delete(mg);
552}
553
554struct symbol *map_groups__find_symbol(struct map_groups *mg,
555 enum map_type type, u64 addr,
556 struct map **mapp)
557{
558 struct map *map = map_groups__find(mg, type, addr);

--- 326 unchanged lines hidden ---
547 map_groups__delete(mg);
548}
549
550struct symbol *map_groups__find_symbol(struct map_groups *mg,
551 enum map_type type, u64 addr,
552 struct map **mapp)
553{
554 struct map *map = map_groups__find(mg, type, addr);

--- 326 unchanged lines hidden ---