hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/tools/perf/util/srcline.c
....@@ -5,11 +5,13 @@
55 #include <string.h>
66
77 #include <linux/kernel.h>
8
+#include <linux/string.h>
9
+#include <linux/zalloc.h>
810
911 #include "util/dso.h"
10
-#include "util/util.h"
1112 #include "util/debug.h"
1213 #include "util/callchain.h"
14
+#include "util/symbol_conf.h"
1315 #include "srcline.h"
1416 #include "string2.h"
1517 #include "symbol.h"
....@@ -301,7 +303,8 @@
301303 }
302304
303305 if (a2l == NULL) {
304
- pr_warning("addr2line_init failed for %s\n", dso_name);
306
+ if (!symbol_conf.disable_add2line_warn)
307
+ pr_warning("addr2line_init failed for %s\n", dso_name);
305308 return 0;
306309 }
307310
....@@ -478,7 +481,7 @@
478481 char *srcline;
479482 struct symbol *inline_sym;
480483
481
- rtrim(funcname);
484
+ strim(funcname);
482485
483486 if (getline(&filename, &filelen, fp) == -1)
484487 goto out;
....@@ -562,6 +565,34 @@
562565 return srcline;
563566 }
564567
568
+/* Returns filename and fills in line number in line */
569
+char *get_srcline_split(struct dso *dso, u64 addr, unsigned *line)
570
+{
571
+ char *file = NULL;
572
+ const char *dso_name;
573
+
574
+ if (!dso->has_srcline)
575
+ goto out;
576
+
577
+ dso_name = dso__name(dso);
578
+ if (dso_name == NULL)
579
+ goto out;
580
+
581
+ if (!addr2line(dso_name, addr, &file, line, dso, true, NULL, NULL))
582
+ goto out;
583
+
584
+ dso->a2l_fails = 0;
585
+ return file;
586
+
587
+out:
588
+ if (dso->a2l_fails && ++dso->a2l_fails > A2L_FAIL_LIMIT) {
589
+ dso->has_srcline = 0;
590
+ dso__free_a2l(dso);
591
+ }
592
+
593
+ return NULL;
594
+}
595
+
565596 void free_srcline(char *srcline)
566597 {
567598 if (srcline && strcmp(srcline, SRCLINE_UNKNOWN) != 0)
....@@ -580,11 +611,12 @@
580611 struct rb_node rb_node;
581612 };
582613
583
-void srcline__tree_insert(struct rb_root *tree, u64 addr, char *srcline)
614
+void srcline__tree_insert(struct rb_root_cached *tree, u64 addr, char *srcline)
584615 {
585
- struct rb_node **p = &tree->rb_node;
616
+ struct rb_node **p = &tree->rb_root.rb_node;
586617 struct rb_node *parent = NULL;
587618 struct srcline_node *i, *node;
619
+ bool leftmost = true;
588620
589621 node = zalloc(sizeof(struct srcline_node));
590622 if (!node) {
....@@ -600,16 +632,18 @@
600632 i = rb_entry(parent, struct srcline_node, rb_node);
601633 if (addr < i->addr)
602634 p = &(*p)->rb_left;
603
- else
635
+ else {
604636 p = &(*p)->rb_right;
637
+ leftmost = false;
638
+ }
605639 }
606640 rb_link_node(&node->rb_node, parent, p);
607
- rb_insert_color(&node->rb_node, tree);
641
+ rb_insert_color_cached(&node->rb_node, tree, leftmost);
608642 }
609643
610
-char *srcline__tree_find(struct rb_root *tree, u64 addr)
644
+char *srcline__tree_find(struct rb_root_cached *tree, u64 addr)
611645 {
612
- struct rb_node *n = tree->rb_node;
646
+ struct rb_node *n = tree->rb_root.rb_node;
613647
614648 while (n) {
615649 struct srcline_node *i = rb_entry(n, struct srcline_node,
....@@ -626,15 +660,15 @@
626660 return NULL;
627661 }
628662
629
-void srcline__tree_delete(struct rb_root *tree)
663
+void srcline__tree_delete(struct rb_root_cached *tree)
630664 {
631665 struct srcline_node *pos;
632
- struct rb_node *next = rb_first(tree);
666
+ struct rb_node *next = rb_first_cached(tree);
633667
634668 while (next) {
635669 pos = rb_entry(next, struct srcline_node, rb_node);
636670 next = rb_next(&pos->rb_node);
637
- rb_erase(&pos->rb_node, tree);
671
+ rb_erase_cached(&pos->rb_node, tree);
638672 free_srcline(pos->srcline);
639673 zfree(&pos);
640674 }
....@@ -668,28 +702,32 @@
668702 free(node);
669703 }
670704
671
-void inlines__tree_insert(struct rb_root *tree, struct inline_node *inlines)
705
+void inlines__tree_insert(struct rb_root_cached *tree,
706
+ struct inline_node *inlines)
672707 {
673
- struct rb_node **p = &tree->rb_node;
708
+ struct rb_node **p = &tree->rb_root.rb_node;
674709 struct rb_node *parent = NULL;
675710 const u64 addr = inlines->addr;
676711 struct inline_node *i;
712
+ bool leftmost = true;
677713
678714 while (*p != NULL) {
679715 parent = *p;
680716 i = rb_entry(parent, struct inline_node, rb_node);
681717 if (addr < i->addr)
682718 p = &(*p)->rb_left;
683
- else
719
+ else {
684720 p = &(*p)->rb_right;
721
+ leftmost = false;
722
+ }
685723 }
686724 rb_link_node(&inlines->rb_node, parent, p);
687
- rb_insert_color(&inlines->rb_node, tree);
725
+ rb_insert_color_cached(&inlines->rb_node, tree, leftmost);
688726 }
689727
690
-struct inline_node *inlines__tree_find(struct rb_root *tree, u64 addr)
728
+struct inline_node *inlines__tree_find(struct rb_root_cached *tree, u64 addr)
691729 {
692
- struct rb_node *n = tree->rb_node;
730
+ struct rb_node *n = tree->rb_root.rb_node;
693731
694732 while (n) {
695733 struct inline_node *i = rb_entry(n, struct inline_node,
....@@ -706,15 +744,15 @@
706744 return NULL;
707745 }
708746
709
-void inlines__tree_delete(struct rb_root *tree)
747
+void inlines__tree_delete(struct rb_root_cached *tree)
710748 {
711749 struct inline_node *pos;
712
- struct rb_node *next = rb_first(tree);
750
+ struct rb_node *next = rb_first_cached(tree);
713751
714752 while (next) {
715753 pos = rb_entry(next, struct inline_node, rb_node);
716754 next = rb_next(&pos->rb_node);
717
- rb_erase(&pos->rb_node, tree);
755
+ rb_erase_cached(&pos->rb_node, tree);
718756 inline_node__delete(pos);
719757 }
720758 }