Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andi Kleen
committed
Apr 11, 2012
1 parent
fc937fd
commit 5362121
Showing
5 changed files
with
111 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
#include "txn-assert.h" | ||
|
||
int foo; | ||
|
||
f2() | ||
{ | ||
TXN_ASSERT_ONLY(foo); | ||
} | ||
|
||
main() | ||
{ | ||
TXN_ASSERT(0); | ||
TXN_ASSERT_ONLY(!foo); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/usr/bin/python | ||
# generate table of TXN_ASSERT() locations and assign unique ids for each | ||
# by patching the binary | ||
# all object files using TXN_ASSERT must be processed on the same command line! | ||
# then the resulting .c file should be compiled and linked in | ||
|
||
import sys | ||
import os | ||
import re | ||
|
||
global identifier | ||
identifier = 0 | ||
|
||
class Section: | ||
def __init__(self, name, foff, vma): | ||
self.name = name | ||
self.foff = foff | ||
self.vaddr = vma | ||
|
||
def addr2line(fn, addr): | ||
a2l = os.popen("addr2line -e %s %#x" % (fn, addr)) | ||
res = a2l.readline() | ||
a2l.close() | ||
return res.rstrip() | ||
|
||
def process(i, pfile): | ||
global identifier | ||
sections = {} | ||
func = None | ||
section = None | ||
objdump = os.popen("objdump -dfh " + i + " | expand", 'r', 8192) | ||
for o in objdump: | ||
if re.match("^Sections:$", o): | ||
for o in objdump: | ||
if re.match(r"\s+\d+\s", o): | ||
(idx, name, size, vma, lma, foff, algn) = o.split() | ||
if name != ".txn_abort": | ||
continue | ||
sections[name] = Section(name, int(foff, 16), int(vma, 16)) | ||
#print >>sys.stderr,"section header %s" % (name,) | ||
if re.match(r"^$", o): | ||
break | ||
m = re.match(r"Disassembly of section ([^:]+):", o) | ||
if m: | ||
if m.group(1) == ".txn_abort": | ||
section = sections[m.group(1)] | ||
else: | ||
section = None | ||
continue | ||
if section: | ||
m = re.match(r"\s+([0-9a-f]+):\s+", o) | ||
if m: | ||
vaddr = int(m.group(1), 16) | ||
if re.match("\s*xabort", o[32:]): | ||
foff = vaddr - section.vaddr + section.foff | ||
if pfile: | ||
print "patch at %d" % (foff + 2,) | ||
if identifier > 254: | ||
# XXX fix assert code to print multiple | ||
print >>sys.stderr, "error: too many txn_asserts" | ||
pfile.seek(foff + 2) | ||
pfile.write("%c" % (identifier & 0xff, )) | ||
m = re.match("\s*jmpq\s+([0-9a-f]+)", o[32:]) | ||
if m: | ||
pos = addr2line(i, int(m.group(1), 16)) | ||
print " [%d] = \"%s\"," % (identifier, pos) | ||
identifier += 1 | ||
|
||
|
||
print "/* Auto generated. Do not edit */" | ||
print "char *txn_assert_table[] = {" | ||
for i in sys.argv[1:]: | ||
pfile = open(i, "r+") | ||
process(i, pfile) | ||
pfile.close() | ||
print "};" | ||
print "int txn_assert_table_size = sizeof(txn_assert_table) / sizeof(char *);" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include "hle.h" | ||
|
||
typedef void (*tsx_assert_hook_t)(unsigned); | ||
extern tsx_assert_hook_t __tsx_set_abort_hook(tsx_assert_hook_t); | ||
|
||
extern char *txn_assert_table[]; | ||
extern int txn_assert_table_size; | ||
|
||
static void assert_hook(unsigned status) | ||
{ | ||
if ((status & XABORT_EXPLICIT_ABORT) && | ||
XABORT_STATUS(status) < txn_assert_table_size) { | ||
write(2, PAIR("txn assert failure at ")); | ||
write(2, txn_assert_table[XABORT_STATUS(status)]); | ||
} | ||
} | ||
|
||
static void __attribute__((constructor)) init_txn_assert(void) | ||
{ | ||
__tsx_set_abort_hook(assert_hook); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters