perf annotate: Introduce ->free() method in ins_ops

So that we don't special case disasm_line__free, allowing each
instruction class to provide an specialized destructor, like is needed
for 'lock'.

Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-xxw4vs5n077tf35jsvjzylhb@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
上级 7a997fe4
...@@ -21,6 +21,14 @@ const char *disassembler_style; ...@@ -21,6 +21,14 @@ const char *disassembler_style;
static struct ins *ins__find(const char *name); static struct ins *ins__find(const char *name);
static int disasm_line__parse(char *line, char **namep, char **rawp); static int disasm_line__parse(char *line, char **namep, char **rawp);
static void ins__delete(struct ins_operands *ops)
{
free(ops->source.raw);
free(ops->source.name);
free(ops->target.raw);
free(ops->target.name);
}
static int ins__raw_scnprintf(struct ins *ins, char *bf, size_t size, static int ins__raw_scnprintf(struct ins *ins, char *bf, size_t size,
struct ins_operands *ops) struct ins_operands *ops)
{ {
...@@ -192,7 +200,15 @@ static int lock__scnprintf(struct ins *ins, char *bf, size_t size, ...@@ -192,7 +200,15 @@ static int lock__scnprintf(struct ins *ins, char *bf, size_t size,
size - printed, ops->locked.ops); size - printed, ops->locked.ops);
} }
static void lock__delete(struct ins_operands *ops)
{
free(ops->locked.ops);
free(ops->target.raw);
free(ops->target.name);
}
static struct ins_ops lock_ops = { static struct ins_ops lock_ops = {
.free = lock__delete,
.parse = lock__parse, .parse = lock__parse,
.scnprintf = lock__scnprintf, .scnprintf = lock__scnprintf,
}; };
...@@ -542,14 +558,10 @@ void disasm_line__free(struct disasm_line *dl) ...@@ -542,14 +558,10 @@ void disasm_line__free(struct disasm_line *dl)
{ {
free(dl->line); free(dl->line);
free(dl->name); free(dl->name);
if (dl->ins && dl->ins->ops == &lock_ops) { if (dl->ins && dl->ins->ops->free)
free(dl->ops.locked.ops); dl->ins->ops->free(&dl->ops);
} else { else
free(dl->ops.source.raw); ins__delete(&dl->ops);
free(dl->ops.source.name);
}
free(dl->ops.target.raw);
free(dl->ops.target.name);
free(dl); free(dl);
} }
......
...@@ -32,6 +32,7 @@ struct ins_operands { ...@@ -32,6 +32,7 @@ struct ins_operands {
}; };
struct ins_ops { struct ins_ops {
void (*free)(struct ins_operands *ops);
int (*parse)(struct ins_operands *ops); int (*parse)(struct ins_operands *ops);
int (*scnprintf)(struct ins *ins, char *bf, size_t size, int (*scnprintf)(struct ins *ins, char *bf, size_t size,
struct ins_operands *ops); struct ins_operands *ops);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册