Bug 11797

Summary: create a gdb.Type from a string "char[10]"
Product: gdb Reporter: Andre' <andre.poenitz>
Component: pythonAssignee: Not yet assigned to anyone <unassigned>
Status: UNCONFIRMED ---    
Severity: normal CC: gdb-prs, jwakely.gcc, meadori, tromey
Priority: P2    
Version: 7.1   
Target Milestone: 7.1   
Host: i486-linux-gnu Target: i486-linux-gnu
Build: i486-linux-gnu Last reconfirmed:

Description Andre' 2010-07-08 16:51:30 UTC
There seems no way to create a gdb.Type from a string "char[10]".

For non-arrays, gdb.lookup_type works:

   str(gdb.lookup_type('char')) == 'char'

but for arrays I get

   gdb.lookup_type('char[10]') 

   -> RuntimeError: No type named char[10].
Comment 1 Meador Inge 2012-01-05 19:07:20 UTC
Use the 'array' method on the constructed gdb.Type instance:

(gdb) py print(gdb.lookup_type('char').array(9))
char [10]
Comment 2 Tom Tromey 2012-01-05 20:41:04 UTC
(In reply to comment #1)
> Use the 'array' method on the constructed gdb.Type instance:
> 
> (gdb) py print(gdb.lookup_type('char').array(9))
> char [10]

Yeah -- but I think what this bug is really about is having
a method like "gdb.parse_type" that will parse a type according
to the language rules.
Comment 3 Andre' 2020-05-25 06:35:58 UTC
Tom is right. 

It would be nice to have a roundtrip gdb.Type -> str(...) -> gdb.Type giving the original type as close as possible.