aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/symbol.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2010-03-25 18:59:00 -0400
committerIngo Molnar <mingo@elte.hu>2010-03-26 03:52:59 -0400
commit5aab621b7bf024608f0c089e21656e7fe875a150 (patch)
tree5fd0da72082d4a60e0d05c727411cd089250d3a3 /tools/perf/util/symbol.c
parent618038df3588fdfcaccfd40057f36ce792bee252 (diff)
perf symbols: Move hex2u64 and strxfrchar to symbol.c
Mostly used in symbol.c so move them there to reduce the number of files needed to use the symbol system. Also do some header adjustments with the same intent. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Frédéric Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Paul Mackerras <paulus@samba.org> LKML-Reference: <1269557941-15617-5-git-send-email-acme@infradead.org> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/util/symbol.c')
-rw-r--r--tools/perf/util/symbol.c85
1 files changed, 67 insertions, 18 deletions
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 3eb9de4baef3..f3d4151e46a1 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -1,13 +1,19 @@
1#include "util.h" 1#define _GNU_SOURCE
2#include "../perf.h" 2#include <ctype.h>
3#include "sort.h" 3#include <dirent.h>
4#include "string.h" 4#include <errno.h>
5#include <libgen.h>
6#include <stdlib.h>
7#include <stdio.h>
8#include <string.h>
9#include <sys/types.h>
10#include <sys/stat.h>
11#include <sys/param.h>
12#include <fcntl.h>
13#include <unistd.h>
5#include "symbol.h" 14#include "symbol.h"
6#include "thread.h" 15#include "strlist.h"
7 16
8#include "debug.h"
9
10#include <asm/bug.h>
11#include <libelf.h> 17#include <libelf.h>
12#include <gelf.h> 18#include <gelf.h>
13#include <elf.h> 19#include <elf.h>
@@ -114,8 +120,8 @@ static void map_groups__fixup_end(struct map_groups *self)
114static struct symbol *symbol__new(u64 start, u64 len, const char *name) 120static struct symbol *symbol__new(u64 start, u64 len, const char *name)
115{ 121{
116 size_t namelen = strlen(name) + 1; 122 size_t namelen = strlen(name) + 1;
117 struct symbol *self = zalloc(symbol_conf.priv_size + 123 struct symbol *self = calloc(1, (symbol_conf.priv_size +
118 sizeof(*self) + namelen); 124 sizeof(*self) + namelen));
119 if (self == NULL) 125 if (self == NULL)
120 return NULL; 126 return NULL;
121 127
@@ -166,7 +172,7 @@ static void dso__set_basename(struct dso *self)
166 172
167struct dso *dso__new(const char *name) 173struct dso *dso__new(const char *name)
168{ 174{
169 struct dso *self = zalloc(sizeof(*self) + strlen(name) + 1); 175 struct dso *self = calloc(1, sizeof(*self) + strlen(name) + 1);
170 176
171 if (self != NULL) { 177 if (self != NULL) {
172 int i; 178 int i;
@@ -1382,13 +1388,13 @@ static int dso__kernel_module_get_build_id(struct dso *self)
1382 return 0; 1388 return 0;
1383} 1389}
1384 1390
1385static int map_groups__set_modules_path_dir(struct map_groups *self, char *dirname) 1391static int map_groups__set_modules_path_dir(struct map_groups *self, char *dir_name)
1386{ 1392{
1387 struct dirent *dent; 1393 struct dirent *dent;
1388 DIR *dir = opendir(dirname); 1394 DIR *dir = opendir(dir_name);
1389 1395
1390 if (!dir) { 1396 if (!dir) {
1391 pr_debug("%s: cannot open %s dir\n", __func__, dirname); 1397 pr_debug("%s: cannot open %s dir\n", __func__, dir_name);
1392 return -1; 1398 return -1;
1393 } 1399 }
1394 1400
@@ -1401,7 +1407,7 @@ static int map_groups__set_modules_path_dir(struct map_groups *self, char *dirna
1401 continue; 1407 continue;
1402 1408
1403 snprintf(path, sizeof(path), "%s/%s", 1409 snprintf(path, sizeof(path), "%s/%s",
1404 dirname, dent->d_name); 1410 dir_name, dent->d_name);
1405 if (map_groups__set_modules_path_dir(self, path) < 0) 1411 if (map_groups__set_modules_path_dir(self, path) < 0)
1406 goto failure; 1412 goto failure;
1407 } else { 1413 } else {
@@ -1421,7 +1427,7 @@ static int map_groups__set_modules_path_dir(struct map_groups *self, char *dirna
1421 continue; 1427 continue;
1422 1428
1423 snprintf(path, sizeof(path), "%s/%s", 1429 snprintf(path, sizeof(path), "%s/%s",
1424 dirname, dent->d_name); 1430 dir_name, dent->d_name);
1425 1431
1426 long_name = strdup(path); 1432 long_name = strdup(path);
1427 if (long_name == NULL) 1433 if (long_name == NULL)
@@ -1458,8 +1464,8 @@ static int map_groups__set_modules_path(struct map_groups *self)
1458 */ 1464 */
1459static struct map *map__new2(u64 start, struct dso *dso, enum map_type type) 1465static struct map *map__new2(u64 start, struct dso *dso, enum map_type type)
1460{ 1466{
1461 struct map *self = zalloc(sizeof(*self) + 1467 struct map *self = calloc(1, (sizeof(*self) +
1462 (dso->kernel ? sizeof(struct kmap) : 0)); 1468 (dso->kernel ? sizeof(struct kmap) : 0)));
1463 if (self != NULL) { 1469 if (self != NULL) {
1464 /* 1470 /*
1465 * ->end will be filled after we load all the symbols 1471 * ->end will be filled after we load all the symbols
@@ -1963,3 +1969,46 @@ int map_groups__create_kernel_maps(struct map_groups *self,
1963 map_groups__fixup_end(self); 1969 map_groups__fixup_end(self);
1964 return 0; 1970 return 0;
1965} 1971}
1972
1973static int hex(char ch)
1974{
1975 if ((ch >= '0') && (ch <= '9'))
1976 return ch - '0';
1977 if ((ch >= 'a') && (ch <= 'f'))
1978 return ch - 'a' + 10;
1979 if ((ch >= 'A') && (ch <= 'F'))
1980 return ch - 'A' + 10;
1981 return -1;
1982}
1983
1984/*
1985 * While we find nice hex chars, build a long_val.
1986 * Return number of chars processed.
1987 */
1988int hex2u64(const char *ptr, u64 *long_val)
1989{
1990 const char *p = ptr;
1991 *long_val = 0;
1992
1993 while (*p) {
1994 const int hex_val = hex(*p);
1995
1996 if (hex_val < 0)
1997 break;
1998
1999 *long_val = (*long_val << 4) | hex_val;
2000 p++;
2001 }
2002
2003 return p - ptr;
2004}
2005
2006char *strxfrchar(char *s, char from, char to)
2007{
2008 char *p = s;
2009
2010 while ((p = strchr(p, from)) != NULL)
2011 *p++ = to;
2012
2013 return s;
2014}