#endif
static void printTypeInfo(link *);
-static void printValAggregates (symbol *,link *,char,unsigned int,int);
+static void printValAggregates (symbol *,link *,char,unsigned int,int,int);
static int printOrSetSymValue (symbol *sym, context *cctxt,
int flg, int dnum, int fmt,
char *rs, char *val, char cmp);
{
char *bp;
char save_ch ;
+ int ptr = 0;
*fmt = FMT_NON;
*sym = NULL;
s++;
s = trim_left(s);
}
+ while (*s == '*') {
+ ptr++;
+ s++;
+ }
for ( bp = s; *bp && ( isalnum( *bp ) || *bp == '_' || *bp == '$'); bp++ );
save_ch = *bp;
if ( *bp )
if ( *s )
*sym = symLookup(s,cctxt);
*bp = save_ch;
+ while (ptr--)
+ strcat(bp,"*");
if ( ! *sym )
fprintf(stdout,"No symbol \"%s\" in current context.\n", s);
fprintf(stdout,"%f",v.f);
else
if (IS_PTR(type))
- fprintf(stdout,"0x%*lx",size<<1,v.val);
+ fprintf(stdout,"0x%0*lx",size<<1,v.val);
else
if (IS_INTEGRAL(type))
{
fprintf(stdout,"print function not yet implemented");
}
+static void
+do_indent(int indent) {
+ while (indent--)
+ fprintf(stdout, " ");
+
+}
+
/*-----------------------------------------------------------------*/
/* printArrayValue - will print the values of array elements */
/*-----------------------------------------------------------------*/
static void printArrayValue (symbol *sym, link *type,
- char space, unsigned int addr, int fmt)
+ char space, unsigned int addr, int fmt,
+ int indent)
{
- link *elem_type = type->next;
- int i;
+ link *elem_type = type->next;
+ int i;
+ int col;
- fprintf(stdout,"{");
- for (i = 0 ; i < DCL_ELEM(type) ; i++) {
- if (IS_AGGREGATE(elem_type)) {
- printValAggregates(sym,elem_type,space,addr,fmt);
- } else {
- printValBasic(sym,elem_type,space,addr,getSize(elem_type),fmt);
- }
- addr += getSize(elem_type);
- if (i != DCL_ELEM(type) -1)
- fprintf(stdout,",");
- }
+ fprintf(stdout,"{");
+ for (i = 0 ; i < DCL_ELEM(type) ; i++) {
+ if (IS_AGGREGATE(elem_type)) {
+ printValAggregates(sym,elem_type,space,addr,fmt,indent);
+ col = 0;
+ } else {
+ printValBasic(sym,elem_type,space,addr,getSize(elem_type),fmt);
+ col++;
+ }
+ addr += getSize(elem_type);
+ if (i != DCL_ELEM(type) -1) {
+ fprintf(stdout,",");
+ if (col == 16) {
+ fprintf(stdout,"\n");
+ do_indent(indent);
+ col = 0;
+ }
+ }
+ }
- fprintf(stdout,"}");
+ fprintf(stdout,"}");
}
/*-----------------------------------------------------------------*/
/* printStructValue - prints structures elements */
/*-----------------------------------------------------------------*/
static void printStructValue (symbol *sym, link *type,
- char space, unsigned int addr, int fmt)
+ char space, unsigned int addr, int fmt,
+ int indent)
{
- symbol *fields = SPEC_STRUCT(type)->fields;
+ symbol *fields = SPEC_STRUCT(type)->fields;
int first = 1;
- fprintf(stdout," { ");
- while (fields) {
- fprintf(stdout,"%s%s = ",(first ? "": ", "),fields->name);
- first = 0;
- if (IS_AGGREGATE(fields->type)) {
- printValAggregates(fields,fields->type,space, addr, fmt);
- } else {
- printValBasic(fields,fields->type,space,addr,getSize(fields->type), fmt);
- }
- addr += getSize(fields->type);
- fields = fields->next;
- }
- fprintf(stdout,"}");
+ do_indent (indent);
+ fprintf(stdout,"{\n");
+ while (fields) {
+ do_indent(indent + 1);
+ fprintf(stdout,"%s = ", fields->name);
+ first = 0;
+ if (IS_AGGREGATE(fields->type)) {
+ printValAggregates(fields,fields->type,space, addr, fmt, indent + 1);
+ } else {
+ printValBasic(fields,fields->type,space,addr,getSize(fields->type), fmt);
+ }
+ fprintf(stdout,",\n");
+ addr += getSize(fields->type);
+ fields = fields->next;
+ }
+ do_indent(indent);
+ fprintf(stdout,"}");
}
/*-----------------------------------------------------------------*/
/* printValAggregates - print value of aggregates */
/*-----------------------------------------------------------------*/
static void printValAggregates (symbol *sym, link *type,
- char space,unsigned int addr, int fmt)
+ char space,unsigned int addr, int fmt,
+ int indent)
{
if (IS_ARRAY(type)) {
- printArrayValue(sym, type, space, addr, fmt);
+ printArrayValue(sym, type, space, addr, fmt, indent);
return ;
}
if (IS_STRUCT(type)) {
- printStructValue(sym, type, space, addr, fmt);
+ printStructValue(sym, type, space, addr, fmt, indent);
return;
}
}
int size, n;
char *s, *s2;
char save_ch, save_ch2;
+ int get_member = 0;
/* if it is on stack then compute address & fall thru */
if (sym->isonstack)
while ( *rs )
{
- if ( *rs == '[' && IS_ARRAY(type))
+ if ( *rs == '[' && (IS_ARRAY(type) || IS_PTR(type)))
{
s = rs+1;
while ( *rs && *rs != ']' ) rs++ ;
{
n = strtol(s,0,0);
}
- if ( n < 0 || n >= DCL_ELEM(type))
+ if ( IS_ARRAY(type) && (n < 0 || n >= DCL_ELEM(type)))
{
fprintf(stdout,"Wrong index %d.\n", n);
return 1;
}
+ if (IS_PTR(type))
+ addr = simGetValue(addr, sym->addrspace, size);
type = type->next;
size = getSize(type);
- addr += size * n;
+ addr += size * n;
*rs++ = save_ch;
}
- else if ( *rs == '.' && IS_STRUCT(type))
+ else if ( (*rs == '.' || get_member) && IS_STRUCT(type))
{
s = rs+1;
/* search structure element */
size = getSize(type);
addr += fields->offset;
}
+ else if ( *rs == '*' && IS_PTR(type))
+ {
+ addr = simGetValue(addr, sym->addrspace, size);
+ type = type->next;
+ size = getSize(type);
+ rs++;
+ }
+ else if ( rs[0] == '-' && rs[1] == '>' &&
+ IS_PTR(type) && IS_STRUCT(type->next))
+ {
+ addr = simGetValue(addr, sym->addrspace, size);
+ type = type->next;
+ size = getSize(type);
+ rs++;
+ get_member = 1;
+ continue;
+ }
else
break;
+ get_member = 0;
}
/* arrays & structures first */
return 1;
}
else
- printValAggregates(sym,type,sym->addrspace,addr,fmt);
+ printValAggregates(sym,type,sym->addrspace,addr,fmt,0);
}
else
/* functions */