From: José Fonseca Date: Wed, 24 Nov 2010 16:19:49 +0000 (+0000) Subject: Refer args by index. X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=dce84c4cbc8176d627c5e7801c2acbd0e2027b86;p=apitrace Refer args by index. Argument names are not very reliable. --- diff --git a/base.py b/base.py index 1637128..8213403 100644 --- a/base.py +++ b/base.py @@ -332,6 +332,7 @@ class Arg: self.type = type self.name = name self.output = output + self.index = None def __str__(self): return '%s %s' % (self.type, self.name) @@ -344,10 +345,13 @@ class Function: self.name = name self.args = [] + index = 0 for arg in args: if isinstance(arg, tuple): arg_type, arg_name = arg arg = Arg(arg_type, arg_name) + arg.index = index + index += 1 self.args.append(arg) self.call = call diff --git a/glretrace.py b/glretrace.py index 4b7ad7a..5cdcf24 100644 --- a/glretrace.py +++ b/glretrace.py @@ -137,7 +137,7 @@ def retrace_function(function): arg_type = ConstRemover().visit(arg.type) print ' // %s -> %s' % (arg.type, arg_type) print ' %s %s;' % (arg_type, arg.name) - rvalue = 'call.arg("%s")' % (arg.name,) + rvalue = 'call.arg(%u)' % (arg.index,) lvalue = arg.name try: ValueExtractor().visit(arg_type, lvalue, rvalue) @@ -156,7 +156,7 @@ def retrace_function(function): for arg in function.args: if arg.output: arg_type = ConstRemover().visit(arg.type) - rvalue = 'call.arg("%s")' % (arg.name,) + rvalue = 'call.arg(%u)' % (arg.index,) lvalue = arg.name try: ValueWrapper().visit(arg_type, lvalue, rvalue) diff --git a/log.cpp b/log.cpp index 5236649..11d0993 100644 --- a/log.cpp +++ b/log.cpp @@ -173,8 +173,9 @@ void EndCall(void) { OS::ReleaseMutex(); } -void BeginArg(const char *name) { +void BeginArg(unsigned index, const char *name) { WriteByte(Trace::CALL_ARG); + WriteUInt(index); WriteString(name); } diff --git a/log.hpp b/log.hpp index fbc9846..b6fc2b3 100644 --- a/log.hpp +++ b/log.hpp @@ -34,7 +34,7 @@ namespace Log { void BeginCall(const char *function); void EndCall(void); - void BeginArg(const char *name); + void BeginArg(unsigned index, const char *name); inline void EndArg(void) {} void BeginReturn(void); diff --git a/trace.py b/trace.py index 8e2e2af..b50d0a6 100644 --- a/trace.py +++ b/trace.py @@ -340,7 +340,7 @@ class Tracer: print def dump_arg(self, function, arg): - print ' Log::BeginArg("%s");' % (arg.name,) + print ' Log::BeginArg(%u, "%s");' % (arg.index, arg.name,) dump_instance(arg.type, arg.name) print ' Log::EndArg();' @@ -402,7 +402,7 @@ class Tracer: print ' %s __result;' % method.type result = '__result = ' print ' Log::BeginCall("%s");' % (interface.name + '::' + method.name) - print ' Log::BeginArg("this");' + print ' Log::BeginArg(0, "this");' print ' Log::LiteralOpaque((const void *)m_pInstance);' print ' Log::EndArg();' for arg in method.args: diff --git a/trace_model.cpp b/trace_model.cpp index f4e915d..098656f 100644 --- a/trace_model.cpp +++ b/trace_model.cpp @@ -153,7 +153,7 @@ public: void visit(Call *call) { const char *sep = ""; os << bold << call->name << normal << "("; - for (std::list::iterator it = call->args.begin(); it != call->args.end(); ++it) { + for (std::vector::iterator it = call->args.begin(); it != call->args.end(); ++it) { os << sep << italic << it->first << normal << " = "; _visit(it->second); sep = ", "; @@ -245,15 +245,6 @@ const char * Value::string(void) const { return NULL; } -Value & Call::arg(const char *name) { - for (std::list::iterator it = args.begin(); it != args.end(); ++it) { - if (it->first == name) { - return *it->second; - } - } - return null; -} - std::ostream & operator <<(std::ostream &os, Call &call) { Dumper d(os); d.visit(&call); diff --git a/trace_model.hpp b/trace_model.hpp index 659b165..f50c6ac 100644 --- a/trace_model.hpp +++ b/trace_model.hpp @@ -236,12 +236,14 @@ class Call { public: std::string name; - std::list args; + std::vector args; Value *ret; Call() : ret(0) { } - Value & arg(const char *name); + inline Value & arg(unsigned index) { + return *(args[index].second); + } }; diff --git a/trace_parser.hpp b/trace_parser.hpp index 2c55037..97dcf65 100644 --- a/trace_parser.hpp +++ b/trace_parser.hpp @@ -86,7 +86,7 @@ public: case Trace::CALL_END: return call; case Trace::CALL_ARG: - call->args.push_back(parse_arg()); + parse_arg(call); break; case Trace::CALL_RET: call->ret = parse_value(); @@ -102,10 +102,14 @@ public: } while(true); } - Arg parse_arg(void) { + void parse_arg(Call *call) { + unsigned index = read_uint(); std::string name = read_string(); Value *value = parse_value(); - return Arg(name, value); + if (index >= call->args.size()) { + call->args.resize(index + 1); + } + call->args[index] = Arg(name, value); } Value *parse_value(void) {