maps.c (659ad3492b913c9033d47cb406ac5754780875b6) maps.c (42fd623b58dbcc48310705bbf3e3d4d7c1deec29)
1// SPDX-License-Identifier: GPL-2.0
2#include <errno.h>
3#include <stdlib.h>
4#include <linux/zalloc.h>
5#include "debug.h"
6#include "dso.h"
7#include "map.h"
8#include "maps.h"

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

501 i++;
502 }
503 up_write(maps__lock(maps));
504}
505
506struct symbol *maps__find_symbol(struct maps *maps, u64 addr, struct map **mapp)
507{
508 struct map *map = maps__find(maps, addr);
1// SPDX-License-Identifier: GPL-2.0
2#include <errno.h>
3#include <stdlib.h>
4#include <linux/zalloc.h>
5#include "debug.h"
6#include "dso.h"
7#include "map.h"
8#include "maps.h"

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

501 i++;
502 }
503 up_write(maps__lock(maps));
504}
505
506struct symbol *maps__find_symbol(struct maps *maps, u64 addr, struct map **mapp)
507{
508 struct map *map = maps__find(maps, addr);
509 struct symbol *result = NULL;
509
510 /* Ensure map is loaded before using map->map_ip */
511 if (map != NULL && map__load(map) >= 0) {
510
511 /* Ensure map is loaded before using map->map_ip */
512 if (map != NULL && map__load(map) >= 0) {
512 if (mapp != NULL)
513 *mapp = map; // TODO: map_put on else path when find returns a get.
514 return map__find_symbol(map, map__map_ip(map, addr));
515 }
513 if (mapp)
514 *mapp = map;
516
515
517 return NULL;
516 result = map__find_symbol(map, map__map_ip(map, addr));
517 if (!mapp)
518 map__put(map);
519 }
520 return result;
518}
519
520struct maps__find_symbol_by_name_args {
521 struct map **mapp;
522 const char *name;
523 struct symbol *sym;
524};
525

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

553 return args.sym;
554}
555
556int maps__find_ams(struct maps *maps, struct addr_map_symbol *ams)
557{
558 if (ams->addr < map__start(ams->ms.map) || ams->addr >= map__end(ams->ms.map)) {
559 if (maps == NULL)
560 return -1;
521}
522
523struct maps__find_symbol_by_name_args {
524 struct map **mapp;
525 const char *name;
526 struct symbol *sym;
527};
528

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

556 return args.sym;
557}
558
559int maps__find_ams(struct maps *maps, struct addr_map_symbol *ams)
560{
561 if (ams->addr < map__start(ams->ms.map) || ams->addr >= map__end(ams->ms.map)) {
562 if (maps == NULL)
563 return -1;
561 ams->ms.map = maps__find(maps, ams->addr); // TODO: map_get
564 ams->ms.map = maps__find(maps, ams->addr);
562 if (ams->ms.map == NULL)
563 return -1;
564 }
565
566 ams->al_addr = map__map_ip(ams->ms.map, ams->addr);
567 ams->ms.sym = map__find_symbol(ams->ms.map, ams->al_addr);
568
569 return ams->ms.sym ? 0 : -1;

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

863 while (!done) {
864 down_read(maps__lock(maps));
865 if (maps__maps_by_address_sorted(maps)) {
866 struct map **mapp =
867 bsearch(&ip, maps__maps_by_address(maps), maps__nr_maps(maps),
868 sizeof(*mapp), map__addr_cmp);
869
870 if (mapp)
565 if (ams->ms.map == NULL)
566 return -1;
567 }
568
569 ams->al_addr = map__map_ip(ams->ms.map, ams->addr);
570 ams->ms.sym = map__find_symbol(ams->ms.map, ams->al_addr);
571
572 return ams->ms.sym ? 0 : -1;

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

866 while (!done) {
867 down_read(maps__lock(maps));
868 if (maps__maps_by_address_sorted(maps)) {
869 struct map **mapp =
870 bsearch(&ip, maps__maps_by_address(maps), maps__nr_maps(maps),
871 sizeof(*mapp), map__addr_cmp);
872
873 if (mapp)
871 result = *mapp; // map__get(*mapp);
874 result = map__get(*mapp);
872 done = true;
873 }
874 up_read(maps__lock(maps));
875 if (!done)
876 maps__sort_by_address(maps);
877 }
878 return result;
879}

--- 215 unchanged lines hidden ---
875 done = true;
876 }
877 up_read(maps__lock(maps));
878 if (!done)
879 maps__sort_by_address(maps);
880 }
881 return result;
882}

--- 215 unchanged lines hidden ---