From: "Jan Beulich" Subject: [PATCH] xenctx: misc adjustments Date: Tue, 11 Jan 2011 10:29:53 +0000 Message-ID: <4D2C3F31020000780002B942@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part09256531.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part09256531.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline - fix off-by-one errors during symbol insertion and lookup - don't store the symbol type, as it wasn't needed at all so far and is only needed now at parsing time - don't insert certain kinds of symbols Signed-off-by: Jan Beulich --- a/tools/xentrace/xenctx.c +++ b/tools/xentrace/xenctx.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -58,7 +59,6 @@ int disp_tlb; =20 struct symbol { guest_word_t address; - char type; char *name; struct symbol *next; } *symbol_table =3D NULL; @@ -112,12 +112,12 @@ static void insert_symbol(struct symbol=20 =20 /* The System.map is usually already sorted... */ if (prev - && prev->address < symbol->address + && prev->address <=3D symbol->address && (!prev->next || prev->next->address > symbol->address)) { s =3D prev; } else { /* ... otherwise do crappy/slow search for the correct place */ - while(s && s->next && s->next->address < symbol->address) + while (s->next && s->next->address <=3D symbol->address) s =3D s->next; } =20 @@ -130,13 +130,13 @@ static struct symbol *lookup_symbol(gues { struct symbol *s =3D symbol_table; =20 - while(s && s->next && s->next->address < address) - s =3D s->next; + if (!s) + return NULL; =20 - if (s && s->address < address) - return s; + while (s->next && s->next->address < address) + s =3D s->next; =20 - return NULL; + return s->next && s->next->address <=3D address ? s->next : s; } =20 static void print_symbol(guest_word_t addr) @@ -159,7 +159,7 @@ static void print_symbol(guest_word_t ad =20 static void read_symbol_table(const char *symtab) { - char line[256]; + char type, line[256]; char *p; struct symbol *symbol; FILE *f; @@ -178,9 +178,13 @@ static void read_symbol_table(const char =20 /* need more checks for syntax here... */ symbol->address =3D strtoull(line, &p, 16); - p++; - symbol->type =3D *p++; - p++; + if (!isspace(*p++)) + continue; + type =3D *p++; + if (!isalpha(type) && type !=3D '?') + continue; + if (!isspace(*p++)) + continue; =20 /* in the future we should handle the module name * being appended here, this would allow us to use @@ -190,7 +194,18 @@ static void read_symbol_table(const char p[strlen(p)-1] =3D '\0'; symbol->name =3D strdup(p); =20 - insert_symbol(symbol); + switch (type) { + case 'A': /* global absolute */ + case 'a': /* local absolute */ + break; + case 'U': /* undefined */ + case 'v': /* undefined weak object */ + case 'w': /* undefined weak function */ + continue; + default: + insert_symbol(symbol); + break; + } =20 if (strcmp(symbol->name, "_stext") =3D=3D 0) kernel_stext =3D symbol->address; --=__Part09256531.0__= Content-Type: text/plain; name="xenctx-misc.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xenctx-misc.patch" - fix off-by-one errors during symbol insertion and lookup=0A- don't store = the symbol type, as it wasn't needed at all so far and=0A is only needed = now at parsing time=0A- don't insert certain kinds of symbols=0A=0ASigned-o= ff-by: Jan Beulich =0A=0A--- a/tools/xentrace/xenctx.c= =0A+++ b/tools/xentrace/xenctx.c=0A@@ -19,6 +19,7 @@=0A #include = =0A #include =0A #include =0A+#include =0A = #include =0A #include =0A #include =0A@@ = -58,7 +59,6 @@ int disp_tlb;=0A =0A struct symbol {=0A guest_word_t = address;=0A- char type;=0A char *name;=0A struct symbol = *next;=0A } *symbol_table =3D NULL;=0A@@ -112,12 +112,12 @@ static void = insert_symbol(struct symbol =0A =0A /* The System.map is usually = already sorted... */=0A if (prev=0A- && prev->address < = symbol->address=0A+ && prev->address <=3D symbol->address=0A = && (!prev->next || prev->next->address > symbol->address)) {=0A s = =3D prev;=0A } else {=0A /* ... otherwise do crappy/slow = search for the correct place */=0A- while(s && s->next && s->next->a= ddress < symbol->address)=0A+ while (s->next && s->next->address = <=3D symbol->address)=0A s =3D s->next;=0A }=0A =0A@@ = -130,13 +130,13 @@ static struct symbol *lookup_symbol(gues=0A {=0A = struct symbol *s =3D symbol_table;=0A =0A- while(s && s->next && = s->next->address < address)=0A- s =3D s->next;=0A+ if (!s)=0A+ = return NULL;=0A =0A- if (s && s->address < address)=0A- = return s;=0A+ while (s->next && s->next->address < address)=0A+ = s =3D s->next;=0A =0A- return NULL;=0A+ return s->next && s->next->ad= dress <=3D address ? s->next : s;=0A }=0A =0A static void print_symbol(gues= t_word_t addr)=0A@@ -159,7 +159,7 @@ static void print_symbol(guest_word_t = ad=0A =0A static void read_symbol_table(const char *symtab)=0A {=0A- = char line[256];=0A+ char type, line[256];=0A char *p;=0A struct = symbol *symbol;=0A FILE *f;=0A@@ -178,9 +178,13 @@ static void = read_symbol_table(const char=0A =0A /* need more checks for syntax = here... */=0A symbol->address =3D strtoull(line, &p, 16);=0A- = p++;=0A- symbol->type =3D *p++;=0A- p++;=0A+ if = (!isspace(*p++))=0A+ continue;=0A+ type =3D *p++;=0A+ = if (!isalpha(type) && type !=3D '?')=0A+ continue;=0A+ = if (!isspace(*p++))=0A+ continue;=0A =0A /* in the = future we should handle the module name=0A * being appended here, = this would allow us to use=0A@@ -190,7 +194,18 @@ static void read_symbol_t= able(const char=0A p[strlen(p)-1] =3D '\0';=0A = symbol->name =3D strdup(p);=0A =0A- insert_symbol(symbol);=0A+ = switch (type) {=0A+ case 'A': /* global absolute */=0A+ = case 'a': /* local absolute */=0A+ break;=0A+ case 'U': = /* undefined */=0A+ case 'v': /* undefined weak object */=0A+ = case 'w': /* undefined weak function */=0A+ continue;=0A+ = default:=0A+ insert_symbol(symbol);=0A+ break;=0A+ = }=0A =0A if (strcmp(symbol->name, "_stext") =3D=3D 0)=0A = kernel_stext =3D symbol->address;=0A --=__Part09256531.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=__Part09256531.0__=--