Create default stab to avoid carrying around stab_t.

This commit is contained in:
Daniel Beer 2010-08-13 12:12:50 +12:00
parent 74e928b318
commit 4cc81497af
9 changed files with 77 additions and 108 deletions

17
cproc.c
View File

@ -43,7 +43,6 @@ struct cproc {
int in_reader_loop;
device_t device;
stab_t stab;
};
static struct cproc_option *find_option(cproc_t cp, const char *name)
@ -199,8 +198,7 @@ static int cmd_help(cproc_t cp, char **arg)
return 0;
}
static int parse_option(stab_t stab,
struct cproc_option *o, const char *word)
static int parse_option(struct cproc_option *o, const char *word)
{
switch (o->type) {
case CPROC_OPTION_BOOL:
@ -210,7 +208,7 @@ static int parse_option(stab_t stab,
break;
case CPROC_OPTION_NUMERIC:
return expr_eval(stab, word, &o->data.numeric);
return expr_eval(stab_default, word, &o->data.numeric);
case CPROC_OPTION_STRING:
strncpy(o->data.text, word, sizeof(o->data.text));
@ -260,7 +258,7 @@ static int cmd_opt(cproc_t cp, char **arg)
}
if (**arg) {
if (parse_option(cp->stab, opt, *arg) < 0) {
if (parse_option(opt, *arg) < 0) {
fprintf(stderr, "opt: can't parse option: %s\n",
*arg);
return -1;
@ -324,7 +322,7 @@ static const struct cproc_option built_in_options[] = {
}
};
cproc_t cproc_new(device_t dev, stab_t st)
cproc_t cproc_new(device_t dev)
{
cproc_t cp = malloc(sizeof(*cp));
@ -334,7 +332,6 @@ cproc_t cproc_new(device_t dev, stab_t st)
memset(cp, 0, sizeof(*cp));
cp->device = dev;
cp->stab = st;
vector_init(&cp->command_list, sizeof(struct cproc_command));
vector_init(&cp->option_list, sizeof(struct cproc_option));
@ -357,7 +354,6 @@ void cproc_destroy(cproc_t cp)
cp->device->destroy(cp->device);
vector_destroy(&cp->command_list);
vector_destroy(&cp->option_list);
stab_destroy(cp->stab);
free(cp);
}
@ -366,11 +362,6 @@ device_t cproc_device(cproc_t cp)
return cp->device;
}
stab_t cproc_stab(cproc_t cp)
{
return cp->stab;
}
int cproc_register_commands(cproc_t cp, const struct cproc_command *cmd,
int count)
{

View File

@ -20,7 +20,6 @@
#define CPROC_H_
#include "device.h"
#include "stab.h"
/* Command processor.
*
@ -90,12 +89,11 @@ struct cproc_option {
* has been given. When you destroy a command processor, the device is
* also destroyed.
*/
cproc_t cproc_new(device_t dev, stab_t st);
cproc_t cproc_new(device_t dev);
void cproc_destroy(cproc_t cp);
/* Fetch the command processor's device and symbol table */
device_t cproc_device(cproc_t cp);
stab_t cproc_stab(cproc_t cp);
/* Register commands and options with the command processor. These functions
* return 0 on success or -1 if an error occurs (failure to allocate memory).

View File

@ -24,7 +24,7 @@
#include "stab.h"
#include "util.h"
static int format_addr(stab_t stab, char *buf, int max_len,
static int format_addr(char *buf, int max_len,
msp430_amode_t amode, uint16_t addr)
{
char name[64];
@ -54,7 +54,7 @@ static int format_addr(stab_t stab, char *buf, int max_len,
if ((!numeric ||
(addr >= 0x200 && addr < 0xfff0)) &&
!stab_nearest(stab, addr, name, sizeof(name), &offset) &&
!stab_nearest(stab_default, addr, name, sizeof(name), &offset) &&
!offset)
return snprintf(buf, max_len,
"%s\x1b[1m%s\x1b[0m", prefix, name);
@ -108,19 +108,19 @@ static int format_reg(char *buf, int max_len,
*
* Returns the number of characters printed.
*/
static int format_operand(stab_t stab, char *buf, int max_len,
static int format_operand(char *buf, int max_len,
msp430_amode_t amode, uint16_t addr,
msp430_reg_t reg)
{
int len = 0;
len += format_addr(stab, buf, max_len, amode, addr);
len += format_addr(buf, max_len, amode, addr);
len += format_reg(buf + len, max_len - len, amode, reg);
return len;
}
/* Write assembly language for the instruction to this buffer */
static int dis_format(stab_t stab, char *buf, int max_len,
static int dis_format(char *buf, int max_len,
const struct msp430_instruction *insn)
{
int len;
@ -157,7 +157,7 @@ static int dis_format(stab_t stab, char *buf, int max_len,
/* Source operand */
if (insn->itype == MSP430_ITYPE_DOUBLE) {
len = format_operand(stab, buf + total,
len = format_operand(buf + total,
max_len - total,
insn->src_mode,
insn->src_addr,
@ -179,7 +179,7 @@ static int dis_format(stab_t stab, char *buf, int max_len,
/* Destination operand */
if (insn->itype != MSP430_ITYPE_NOARG)
total += format_operand(stab, buf + total,
total += format_operand(buf + total,
max_len - total,
insn->dst_mode,
insn->dst_addr,
@ -207,7 +207,6 @@ static int dis_format(stab_t stab, char *buf, int max_len,
void cproc_disassemble(cproc_t cp,
address_t offset, const uint8_t *data, int length)
{
stab_t stab = cproc_stab(cp);
int first_line = 1;
while (length) {
@ -220,7 +219,7 @@ void cproc_disassemble(cproc_t cp,
char buf[256];
int len = 0;
if (!stab_nearest(stab, offset, obname, sizeof(obname),
if (!stab_nearest(stab_default, offset, obname, sizeof(obname),
&oboff)) {
if (!oboff)
cproc_printf(cp, "\x1b[m%s:\x1b[0m", obname);
@ -250,7 +249,7 @@ void cproc_disassemble(cproc_t cp,
}
if (retval >= 0)
len += dis_format(stab, buf + len, sizeof(buf) - len,
len += dis_format(buf + len, sizeof(buf) - len,
&insn);
buf[len] = 0;

View File

@ -54,7 +54,6 @@ static int cmd_regs(cproc_t cp, char **arg)
static int cmd_md(cproc_t cp, char **arg)
{
stab_t stab = cproc_stab(cp);
device_t dev = cproc_device(cp);
char *off_text = get_arg(arg);
char *len_text = get_arg(arg);
@ -66,13 +65,13 @@ static int cmd_md(cproc_t cp, char **arg)
return -1;
}
if (expr_eval(stab, off_text, &offset) < 0) {
if (expr_eval(stab_default, off_text, &offset) < 0) {
fprintf(stderr, "md: can't parse offset: %s\n", off_text);
return -1;
}
if (len_text) {
if (expr_eval(stab, len_text, &length) < 0) {
if (expr_eval(stab_default, len_text, &length) < 0) {
fprintf(stderr, "md: can't parse length: %s\n",
len_text);
return -1;
@ -99,7 +98,6 @@ static int cmd_md(cproc_t cp, char **arg)
static int cmd_mw(cproc_t cp, char **arg)
{
device_t dev = cproc_device(cp);
stab_t stab = cproc_stab(cp);
char *off_text = get_arg(arg);
char *byte_text;
address_t offset = 0;
@ -111,7 +109,7 @@ static int cmd_mw(cproc_t cp, char **arg)
return -1;
}
if (expr_eval(stab, off_text, &offset) < 0) {
if (expr_eval(stab_default, off_text, &offset) < 0) {
fprintf(stderr, "md: can't parse offset: %s\n", off_text);
return -1;
}
@ -222,7 +220,6 @@ static int cmd_run(cproc_t cp, char **arg)
static int cmd_set(cproc_t cp, char **arg)
{
device_t dev = cproc_device(cp);
stab_t stab = cproc_stab(cp);
char *reg_text = get_arg(arg);
char *val_text = get_arg(arg);
int reg;
@ -240,7 +237,7 @@ static int cmd_set(cproc_t cp, char **arg)
return -1;
}
if (expr_eval(stab, val_text, &value) < 0) {
if (expr_eval(stab_default, val_text, &value) < 0) {
fprintf(stderr, "set: can't parse value: %s\n", val_text);
return -1;
}
@ -258,7 +255,6 @@ static int cmd_set(cproc_t cp, char **arg)
static int cmd_dis(cproc_t cp, char **arg)
{
device_t dev = cproc_device(cp);
stab_t stab = cproc_stab(cp);
char *off_text = get_arg(arg);
char *len_text = get_arg(arg);
address_t offset = 0;
@ -270,13 +266,13 @@ static int cmd_dis(cproc_t cp, char **arg)
return -1;
}
if (expr_eval(stab, off_text, &offset) < 0) {
if (expr_eval(stab_default, off_text, &offset) < 0) {
fprintf(stderr, "dis: can't parse offset: %s\n", off_text);
return -1;
}
if (len_text) {
if (expr_eval(stab, len_text, &length) < 0) {
if (expr_eval(stab_default, len_text, &length) < 0) {
fprintf(stderr, "dis: can't parse length: %s\n",
len_text);
return -1;
@ -408,7 +404,6 @@ static int hexout_feed(struct hexout_data *hexout,
static int cmd_hexout(cproc_t cp, char **arg)
{
device_t dev = cproc_device(cp);
stab_t stab = cproc_stab(cp);
char *off_text = get_arg(arg);
char *len_text = get_arg(arg);
char *filename = *arg;
@ -421,8 +416,8 @@ static int cmd_hexout(cproc_t cp, char **arg)
return -1;
}
if (expr_eval(stab, off_text, &off) < 0 ||
expr_eval(stab, len_text, &length) < 0)
if (expr_eval(stab_default, off_text, &off) < 0 ||
expr_eval(stab_default, len_text, &length) < 0)
return -1;
if (hexout_start(&hexout, filename) < 0)
@ -547,7 +542,6 @@ static int prog_feed(void *user_data,
static int cmd_prog(cproc_t cp, char **arg)
{
device_t dev = cproc_device(cp);
stab_t stab = cproc_stab(cp);
FILE *in;
struct prog_data prog;
@ -573,8 +567,8 @@ static int cmd_prog(cproc_t cp, char **arg)
}
if (binfile_info(in) & BINFILE_HAS_SYMS) {
stab_clear(stab);
binfile_syms(in, stab);
stab_clear(stab_default);
binfile_syms(in, stab_default);
}
fclose(in);
@ -594,7 +588,6 @@ static int cmd_prog(cproc_t cp, char **arg)
static int cmd_setbreak(cproc_t cp, char **arg)
{
device_t dev = cproc_device(cp);
stab_t stab = cproc_stab(cp);
char *addr_text = get_arg(arg);
char *index_text = get_arg(arg);
int index = -1;
@ -605,7 +598,7 @@ static int cmd_setbreak(cproc_t cp, char **arg)
return -1;
}
if (expr_eval(stab, addr_text, &addr) < 0) {
if (expr_eval(stab_default, addr_text, &addr) < 0) {
fprintf(stderr, "setbreak: invalid address\n");
return -1;
}
@ -662,7 +655,6 @@ static int cmd_delbreak(cproc_t cp, char **arg)
static int cmd_break(cproc_t cp, char **arg)
{
device_t dev = cproc_device(cp);
stab_t stab = cproc_stab(cp);
int i;
printf("%d breakpoints available:\n", dev->max_breakpoints);
@ -674,7 +666,7 @@ static int cmd_break(cproc_t cp, char **arg)
address_t offset;
printf(" %d. 0x%05x", i, bp->addr);
if (!stab_nearest(stab, bp->addr, name,
if (!stab_nearest(stab_default, bp->addr, name,
sizeof(name), &offset)) {
printf(" (%s", name);
if (offset)

33
main.c
View File

@ -46,14 +46,13 @@
#include "olimex.h"
#include "rf2500.h"
static void io_prefix(stab_t stab,
const char *prefix, uint16_t pc,
static void io_prefix(const char *prefix, uint16_t pc,
uint16_t addr, int is_byte)
{
char name[64];
address_t offset;
if (!stab_nearest(stab, pc, name, sizeof(name), &offset)) {
if (!stab_nearest(stab_default, pc, name, sizeof(name), &offset)) {
printf("%s", name);
if (offset)
printf("+0x%x", offset);
@ -62,7 +61,7 @@ static void io_prefix(stab_t stab,
}
printf(": IO %s.%c: 0x%04x", prefix, is_byte ? 'B' : 'W', addr);
if (!stab_nearest(stab, addr, name, sizeof(name), &offset)) {
if (!stab_nearest(stab_default, addr, name, sizeof(name), &offset)) {
printf(" (%s", name);
if (offset)
printf("+0x%x", offset);
@ -73,9 +72,7 @@ static void io_prefix(stab_t stab,
static int fetch_io(void *user_data, uint16_t pc,
uint16_t addr, int is_byte, uint16_t *data_ret)
{
stab_t stab = (stab_t)user_data;
io_prefix(stab, "READ", pc, addr, is_byte);
io_prefix("READ", pc, addr, is_byte);
for (;;) {
char text[128];
@ -97,7 +94,7 @@ static int fetch_io(void *user_data, uint16_t pc,
if (!len)
return 0;
if (!expr_eval(stab, text, &data)) {
if (!expr_eval(stab_default, text, &data)) {
if (data_ret)
*data_ret = data;
return 0;
@ -110,9 +107,7 @@ static int fetch_io(void *user_data, uint16_t pc,
static void store_io(void *user_data, uint16_t pc,
uint16_t addr, int is_byte, uint16_t data)
{
stab_t stab = (stab_t)user_data;
io_prefix(stab, "WRITE", pc, addr, is_byte);
io_prefix("WRITE", pc, addr, is_byte);
if (is_byte)
printf(" => 0x%02x\n", data & 0xff);
@ -128,7 +123,6 @@ struct cmdline_args {
int want_jtag;
int no_rc;
int vcc_mv;
stab_t stab;
};
struct driver {
@ -187,7 +181,7 @@ static device_t driver_open_olimex(const struct cmdline_args *args)
static device_t driver_open_sim(const struct cmdline_args *args)
{
return sim_open(fetch_io, store_io, args->stab);
return sim_open(fetch_io, store_io, NULL);
}
static device_t driver_open_uif(const struct cmdline_args *args)
@ -414,7 +408,6 @@ cproc_t setup_cproc(struct cmdline_args *args)
{
int i;
device_t msp430_dev;
stab_t stab;
cproc_t cp;
i = 0;
@ -427,21 +420,20 @@ cproc_t setup_cproc(struct cmdline_args *args)
return NULL;
}
stab = stab_new();
if (!stab)
stab_default = stab_new();
if (!stab_default)
return NULL;
args->stab = stab;
msp430_dev = driver_table[i].func(args);
if (!msp430_dev) {
stab_destroy(stab);
stab_destroy(stab_default);
return NULL;
}
cp = cproc_new(msp430_dev, stab);
cp = cproc_new(msp430_dev);
if (!cp) {
msp430_dev->destroy(msp430_dev);
stab_destroy(stab);
stab_destroy(stab_default);
return NULL;
}
@ -495,6 +487,7 @@ int main(int argc, char **argv)
}
cproc_destroy(cp);
stab_destroy(stab_default);
return ret;
}

View File

@ -154,7 +154,7 @@ static int isearch_addr(cproc_t cp, const char *term, char **arg,
return -1;
}
if (expr_eval(cproc_stab(cp), addr_text, &addr) < 0)
if (expr_eval(stab_default, addr_text, &addr) < 0)
return -1;
q->flags |= which;
@ -397,7 +397,6 @@ static int cmd_isearch(cproc_t cp, char **arg)
{"dstmode", isearch_mode}
};
stab_t stab = cproc_stab(cp);
struct isearch_query q;
const char *addr_text;
const char *len_text;
@ -412,8 +411,8 @@ static int cmd_isearch(cproc_t cp, char **arg)
return -1;
}
if (expr_eval(stab, addr_text, &addr) < 0 ||
expr_eval(stab, len_text, &len) < 0)
if (expr_eval(stab_default, addr_text, &addr) < 0 ||
expr_eval(stab_default, len_text, &len) < 0)
return -1;
q.flags = 0;
@ -745,7 +744,7 @@ static int add_symbol_nodes(void *user_data, const char *name,
}
static int cgraph_init(address_t offset, address_t len, uint8_t *memory,
struct call_graph *graph, stab_t stab)
struct call_graph *graph)
{
vector_init(&graph->edge_to, sizeof(struct cg_edge));
vector_init(&graph->edge_from, sizeof(struct cg_edge));
@ -759,7 +758,7 @@ static int cgraph_init(address_t offset, address_t len, uint8_t *memory,
if (add_irq_edges(offset, len, memory, graph) < 0)
goto fail;
if (stab_enum(stab, add_symbol_nodes, graph) < 0)
if (stab_enum(stab_default, add_symbol_nodes, graph) < 0)
goto fail;
if (add_nodes_from_edges(graph) < 0)
goto fail;
@ -780,7 +779,6 @@ static int cgraph_init(address_t offset, address_t len, uint8_t *memory,
static void cgraph_summary(struct call_graph *graph, cproc_t cp)
{
stab_t stab = cproc_stab(cp);
int i;
int j = 0; /* Edge from index */
int k = 0; /* Edge to index */
@ -812,7 +810,8 @@ static void cgraph_summary(struct call_graph *graph, cproc_t cp)
k++;
}
if (stab_nearest(stab, n->offset, name, sizeof(name), &o) ||
if (stab_nearest(stab_default, n->offset,
name, sizeof(name), &o) ||
o)
name[0] = 0;
@ -824,7 +823,6 @@ static void cgraph_summary(struct call_graph *graph, cproc_t cp)
static void cgraph_func_info(struct call_graph *graph, cproc_t cp,
int addr)
{
stab_t stab = cproc_stab(cp);
int i = 0;
int j = 0;
int k = 0;
@ -851,7 +849,8 @@ static void cgraph_func_info(struct call_graph *graph, cproc_t cp,
CG_EDGE_TO(graph, k)->dst < n->offset)
k++;
if (stab_nearest(stab, n->offset, name, sizeof(name), &offset))
if (stab_nearest(stab_default, n->offset,
name, sizeof(name), &offset))
printf("0x%04x:\n", n->offset);
else if (offset)
printf("0x%04x %s+0x%x:\n", n->offset, name, offset);
@ -867,7 +866,8 @@ static void cgraph_func_info(struct call_graph *graph, cproc_t cp,
if (e->src != n->offset)
break;
if (stab_nearest(stab, e->dst, name, sizeof(name),
if (stab_nearest(stab_default, e->dst,
name, sizeof(name),
&offset) ||
offset)
snprintf(name, sizeof(name), "0x%04x", e->dst);
@ -888,7 +888,8 @@ static void cgraph_func_info(struct call_graph *graph, cproc_t cp,
if (e->dst != n->offset)
break;
if (stab_nearest(stab, e->src, name, sizeof(name),
if (stab_nearest(stab_default, e->src,
name, sizeof(name),
&offset) ||
offset)
snprintf(name, sizeof(name), "0x%04x", e->src);
@ -902,7 +903,6 @@ static void cgraph_func_info(struct call_graph *graph, cproc_t cp,
static int cmd_cgraph(cproc_t cp, char **arg)
{
stab_t stab = cproc_stab(cp);
device_t dev = cproc_device(cp);
char *offset_text, *len_text, *addr_text;;
address_t offset, len, addr;
@ -920,19 +920,19 @@ static int cmd_cgraph(cproc_t cp, char **arg)
return -1;
}
if (expr_eval(stab, offset_text, &offset) < 0) {
if (expr_eval(stab_default, offset_text, &offset) < 0) {
fprintf(stderr, "cgraph: invalid offset: %s\n", offset_text);
return -1;
}
offset &= ~1;
if (expr_eval(stab, len_text, &len) < 0) {
if (expr_eval(stab_default, len_text, &len) < 0) {
fprintf(stderr, "cgraph: invalid length: %s\n", len_text);
return -1;
}
len &= ~1;
if (addr_text && expr_eval(stab, addr_text, &addr) < 0) {
if (addr_text && expr_eval(stab_default, addr_text, &addr) < 0) {
fprintf(stderr, "cgraph: invalid address: %s\n", addr_text);
return -1;
}
@ -952,7 +952,7 @@ static int cmd_cgraph(cproc_t cp, char **arg)
}
/* Produce and display the call graph */
if (cgraph_init(offset, len, memory, &graph, cproc_stab(cp)) < 0) {
if (cgraph_init(offset, len, memory, &graph) < 0) {
fprintf(stderr, "cgraph: couldn't build call graph\n");
free(memory);
return -1;

2
stab.c
View File

@ -28,6 +28,8 @@
#include "stab.h"
#include "util.h"
stab_t stab_default;
/************************************************************************
* B+Tree definitions
*/

2
stab.h
View File

@ -25,6 +25,8 @@
struct stab;
typedef struct stab *stab_t;
extern stab_t stab_default;
/* Create/destroy a symbol table. The constructor returns NULL if it
* was unable to allocate memory for the table.
*/

42
sym.c
View File

@ -32,18 +32,17 @@
static int cmd_eval(cproc_t cp, char **arg)
{
stab_t stab = cproc_stab(cp);
address_t addr;
address_t offset;
char name[64];
if (expr_eval(stab, *arg, &addr) < 0) {
if (expr_eval(stab_default, *arg, &addr) < 0) {
fprintf(stderr, "=: can't parse: %s\n", *arg);
return -1;
}
printf("0x%05x", addr);
if (!stab_nearest(stab, addr, name, sizeof(name), &offset)) {
if (!stab_nearest(stab_default, addr, name, sizeof(name), &offset)) {
printf(" = %s", name);
if (offset)
printf("+0x%x", offset);
@ -55,7 +54,6 @@ static int cmd_eval(cproc_t cp, char **arg)
static int cmd_sym_load_add(cproc_t cp, int clear, char **arg)
{
stab_t stab = cproc_stab(cp);
FILE *in;
if (clear && cproc_prompt_abort(cp, CPROC_MODIFY_SYMS))
@ -68,13 +66,13 @@ static int cmd_sym_load_add(cproc_t cp, int clear, char **arg)
}
if (clear) {
stab_clear(stab);
stab_clear(stab_default);
cproc_unmodify(cp, CPROC_MODIFY_SYMS);
} else {
cproc_modify(cp, CPROC_MODIFY_SYMS);
}
if (binfile_syms(in, stab) < 0) {
if (binfile_syms(in, stab_default) < 0) {
fclose(in);
return -1;
}
@ -97,7 +95,6 @@ static int savemap_cb(void *user_data, const char *name, address_t value)
static int cmd_sym_savemap(cproc_t cp, char **arg)
{
stab_t stab = cproc_stab(cp);
FILE *savemap_out;
char *fname = get_arg(arg);
@ -113,7 +110,7 @@ static int cmd_sym_savemap(cproc_t cp, char **arg)
return -1;
}
if (stab_enum(stab, savemap_cb, savemap_out) < 0) {
if (stab_enum(stab_default, savemap_cb, savemap_out) < 0) {
fclose(savemap_out);
return -1;
}
@ -145,12 +142,11 @@ static int find_sym(void *user_data, const char *name, address_t value)
static int cmd_sym_find(cproc_t cp, char **arg)
{
stab_t stab = cproc_stab(cp);
regex_t find_preg;
char *expr = get_arg(arg);
if (!expr) {
stab_enum(stab, print_sym, NULL);
stab_enum(stab_default, print_sym, NULL);
return 0;
}
@ -159,7 +155,7 @@ static int cmd_sym_find(cproc_t cp, char **arg)
return -1;
}
stab_enum(stab, find_sym, &find_preg);
stab_enum(stab_default, find_sym, &find_preg);
regfree(&find_preg);
return 0;
}
@ -174,8 +170,7 @@ struct rename_data {
regex_t preg;
};
static int renames_do(stab_t stab,
struct rename_data *rename, const char *replace)
static int renames_do(struct rename_data *rename, const char *replace)
{
int i;
int count = 0;
@ -197,13 +192,13 @@ static int renames_do(stab_t stab,
printf("%s -> %s\n", r->old_name, new_name);
if (stab_get(stab, r->old_name, &value) < 0) {
if (stab_get(stab_default, r->old_name, &value) < 0) {
fprintf(stderr, "sym: warning: "
"symbol missing: %s\n",
r->old_name);
} else {
stab_del(stab, r->old_name);
if (stab_set(stab, new_name, value) < 0) {
stab_del(stab_default, r->old_name);
if (stab_set(stab_default, new_name, value) < 0) {
fprintf(stderr, "sym: warning: "
"failed to set new name: %s\n",
new_name);
@ -243,7 +238,6 @@ static int cmd_sym_rename(cproc_t cp, char **arg)
const char *replace = get_arg(arg);
int ret;
struct rename_data rename;
stab_t stab = cproc_stab(cp);
if (!(expr && replace)) {
fprintf(stderr, "sym: expected pattern and replacement\n");
@ -257,7 +251,7 @@ static int cmd_sym_rename(cproc_t cp, char **arg)
vector_init(&rename.list, sizeof(struct rename_record));
if (stab_enum(stab, find_renames, &rename) < 0) {
if (stab_enum(stab_default, find_renames, &rename) < 0) {
fprintf(stderr, "sym: rename failed\n");
regfree(&rename.preg);
vector_destroy(&rename.list);
@ -265,7 +259,7 @@ static int cmd_sym_rename(cproc_t cp, char **arg)
}
regfree(&rename.preg);
ret = renames_do(stab, &rename, replace);
ret = renames_do(&rename, replace);
vector_destroy(&rename.list);
if (ret > 0)
@ -276,7 +270,6 @@ static int cmd_sym_rename(cproc_t cp, char **arg)
static int cmd_sym_del(cproc_t cp, char **arg)
{
stab_t stab = cproc_stab(cp);
char *name = get_arg(arg);
if (!name) {
@ -285,7 +278,7 @@ static int cmd_sym_del(cproc_t cp, char **arg)
return -1;
}
if (stab_del(stab, name) < 0) {
if (stab_del(stab_default, name) < 0) {
fprintf(stderr, "sym: can't delete nonexistent symbol: %s\n",
name);
return -1;
@ -297,7 +290,6 @@ static int cmd_sym_del(cproc_t cp, char **arg)
static int cmd_sym(cproc_t cp, char **arg)
{
stab_t stab = cproc_stab(cp);
char *subcmd = get_arg(arg);
if (!subcmd) {
@ -309,7 +301,7 @@ static int cmd_sym(cproc_t cp, char **arg)
if (!strcasecmp(subcmd, "clear")) {
if (cproc_prompt_abort(cp, CPROC_MODIFY_SYMS))
return 0;
stab_clear(stab);
stab_clear(stab_default);
cproc_unmodify(cp, CPROC_MODIFY_SYMS);
return 0;
}
@ -325,13 +317,13 @@ static int cmd_sym(cproc_t cp, char **arg)
return -1;
}
if (expr_eval(stab, val_text, &value) < 0) {
if (expr_eval(stab_default, val_text, &value) < 0) {
fprintf(stderr, "sym: can't parse value: %s\n",
val_text);
return -1;
}
if (stab_set(stab, name, value) < 0)
if (stab_set(stab_default, name, value) < 0)
return -1;
cproc_modify(cp, CPROC_MODIFY_SYMS);