From: Weimin Pan <weimin.pan@oracle.com>
To: gdb-patches@sourceware.org
Subject: [PATCH,V2 3/5] CTF: handle forward reference type
Date: Mon, 1 Mar 2021 20:53:36 -0500 [thread overview]
Message-ID: <1614650018-9135-4-git-send-email-weimin.pan@oracle.com> (raw)
In-Reply-To: <1614650018-9135-3-git-send-email-weimin.pan@oracle.com>
Added function fetch_tid_type which calls get_tid_type and will set up
the type, associated with a tid, if it is not read in yet. Also implement
function read_forward_type which handles the CTF_K_FORWARD kind.
Expanded gdb.base/ctf-ptype.exp to add cases with forward references.
---
gdb/ChangeLog | 6 +++
gdb/ctfread.c | 78 ++++++++++++++++++++++++++++++------
gdb/testsuite/ChangeLog | 6 +++
gdb/testsuite/gdb.base/ctf-ptype.c | 12 ++++++
gdb/testsuite/gdb.base/ctf-ptype.exp | 2 +
5 files changed, 91 insertions(+), 13 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 0a839ba..dac61a3 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@
2021-02-26 Weimin Pan <weimin.pan@oracle.com>
+ * ctfread.c (fetch_tid_type): New function, use throughout file.
+ (read_forward_type): New function.
+ (read_type_record): Call read_forward_type.
+
+2021-02-26 Weimin Pan <weimin.pan@oracle.com>
+
* ctfread.c (read_func_kind_type): Set up function arguments.
2021-02-26 Weimin Pan <weimin.pan@oracle.com>
diff --git a/gdb/ctfread.c b/gdb/ctfread.c
index 75b098c..d3e6ad5 100644
--- a/gdb/ctfread.c
+++ b/gdb/ctfread.c
@@ -186,6 +186,8 @@ static struct type *read_typedef_type (struct ctf_context *cp, ctf_id_t tid,
static void process_struct_members (struct ctf_context *cp, ctf_id_t tid,
struct type *type);
+static struct type *read_forward_type (struct ctf_context *cp, ctf_id_t tid);
+
static struct symbol *new_symbol (struct ctf_context *cp, struct type *type,
ctf_id_t tid);
@@ -269,6 +271,25 @@ struct ctf_tid_and_type
return NULL;
}
+/* Fetch the type for TID in CCP OF's tid_and_type hash, add the type to
+ context CCP if hash is empty or TID does not have a saved type. */
+
+static struct type *
+fetch_tid_type (struct ctf_context *ccp, ctf_id_t tid)
+{
+ struct objfile *of = ccp->of;
+ struct type *typ;
+
+ typ = get_tid_type (of, tid);
+ if (typ == NULL)
+ {
+ ctf_add_type_cb (tid, ccp);
+ typ = get_tid_type (of, tid);
+ }
+
+ return typ;
+}
+
/* Return the size of storage in bits for INTEGER, FLOAT, or ENUM. */
static int
@@ -368,7 +389,7 @@ struct ctf_tid_and_type
FIELD_NAME (*fp) = name;
kind = ctf_type_kind (ccp->fp, tid);
- t = get_tid_type (ccp->of, tid);
+ t = fetch_tid_type (ccp, tid);
if (t == NULL)
{
t = read_type_record (ccp, tid);
@@ -660,7 +681,7 @@ struct ctf_tid_and_type
type->set_code (TYPE_CODE_FUNC);
ctf_func_type_info (fp, tid, &cfi);
- rettype = get_tid_type (of, cfi.ctc_return);
+ rettype = fetch_tid_type (ccp, cfi.ctc_return);
TYPE_TARGET_TYPE (type) = rettype;
set_type_align (type, ctf_type_align (fp, tid));
@@ -787,11 +808,11 @@ struct ctf_tid_and_type
return NULL;
}
- element_type = get_tid_type (objfile, ar.ctr_contents);
+ element_type = fetch_tid_type (ccp, ar.ctr_contents);
if (element_type == NULL)
return NULL;
- idx_type = get_tid_type (objfile, ar.ctr_index);
+ idx_type = fetch_tid_type (ccp, ar.ctr_index);
if (idx_type == NULL)
idx_type = objfile_type (objfile)->builtin_int;
@@ -819,7 +840,7 @@ struct ctf_tid_and_type
struct objfile *objfile = ccp->of;
struct type *base_type, *cv_type;
- base_type = get_tid_type (objfile, btid);
+ base_type = fetch_tid_type (ccp, btid);
if (base_type == NULL)
{
base_type = read_type_record (ccp, btid);
@@ -843,7 +864,7 @@ struct ctf_tid_and_type
ctf_dict_t *fp = ccp->fp;
struct type *base_type, *cv_type;
- base_type = get_tid_type (objfile, btid);
+ base_type = fetch_tid_type (ccp, btid);
if (base_type == NULL)
{
base_type = read_type_record (ccp, btid);
@@ -869,7 +890,7 @@ struct ctf_tid_and_type
struct objfile *objfile = ccp->of;
struct type *base_type, *cv_type;
- base_type = get_tid_type (objfile, btid);
+ base_type = fetch_tid_type (ccp, btid);
if (base_type == NULL)
{
base_type = read_type_record (ccp, btid);
@@ -896,7 +917,7 @@ struct ctf_tid_and_type
char *aname = obstack_strdup (&objfile->objfile_obstack, name);
this_type = init_type (objfile, TYPE_CODE_TYPEDEF, 0, aname);
set_tid_type (objfile, tid, this_type);
- target_type = get_tid_type (objfile, btid);
+ target_type = fetch_tid_type (ccp, btid);
if (target_type != this_type)
TYPE_TARGET_TYPE (this_type) = target_type;
else
@@ -915,7 +936,7 @@ struct ctf_tid_and_type
struct objfile *of = ccp->of;
struct type *target_type, *type;
- target_type = get_tid_type (of, btid);
+ target_type = fetch_tid_type (ccp, btid);
if (target_type == NULL)
{
target_type = read_type_record (ccp, btid);
@@ -932,6 +953,34 @@ struct ctf_tid_and_type
return set_tid_type (of, tid, type);
}
+/* Read all information from a TID of CTF_K_FORWARD. */
+
+static struct type *
+read_forward_type (struct ctf_context *ccp, ctf_id_t tid)
+{
+ struct objfile *of = ccp->of;
+ ctf_dict_t *fp = ccp->fp;
+ struct type *type;
+ uint32_t kind;
+
+ type = alloc_type (of);
+
+ gdb::unique_xmalloc_ptr<char> name (ctf_type_aname_raw (fp, tid));
+ if (name != NULL && strlen (name.get() ) != 0)
+ type->set_name (obstack_strdup (&of->objfile_obstack, name.get ()));
+
+ kind = ctf_type_kind_forwarded (fp, tid);
+ if (kind == CTF_K_UNION)
+ type->set_code (TYPE_CODE_UNION);
+ else
+ type->set_code (TYPE_CODE_STRUCT);
+
+ TYPE_LENGTH (type) = 0;
+ type->set_is_stub (true);
+
+ return set_tid_type (of, tid, type);
+}
+
/* Read information associated with type TID. */
static struct type *
@@ -985,6 +1034,9 @@ struct ctf_tid_and_type
case CTF_K_ARRAY:
type = read_array_type (ccp, tid);
break;
+ case CTF_K_FORWARD:
+ type = read_forward_type (ccp, tid);
+ break;
case CTF_K_UNKNOWN:
break;
default:
@@ -1131,7 +1183,7 @@ struct ctf_tid_and_type
if ((tid = ctf_lookup_by_symbol (ccp->fp, idx)) == CTF_ERR)
return NULL;
- type = get_tid_type (ccp->of, tid);
+ type = fetch_tid_type (ccp, tid);
if (type == NULL)
return NULL;
@@ -1165,7 +1217,7 @@ struct ctf_tid_and_type
return NULL;
tid = ctf_lookup_by_symbol (ccp->fp, idx);
- ftype = get_tid_type (ccp->of, tid);
+ ftype = fetch_tid_type (ccp, tid);
if (finfo.ctc_flags & CTF_FUNC_VARARG)
ftype->set_has_varargs (true);
ftype->set_num_fields (argc);
@@ -1179,7 +1231,7 @@ struct ctf_tid_and_type
to find the argument type. */
for (int iparam = 0; iparam < argc; iparam++)
{
- atyp = get_tid_type (ccp->of, argv[iparam]);
+ atyp = fetch_tid_type (ccp, argv[iparam]);
if (atyp)
ftype->field (iparam).set_type (atyp);
else
@@ -1187,7 +1239,7 @@ struct ctf_tid_and_type
}
sym = new_symbol (ccp, ftype, tid);
- rettyp = get_tid_type (ccp->of, finfo.ctc_return);
+ rettyp = fetch_tid_type (ccp, finfo.ctc_return);
if (rettyp != NULL)
SYMBOL_TYPE (sym) = rettyp;
else
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 9445362..4f9a3ec 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,11 @@
2021-02-26 Weimin Pan <weimin.pan@oracle.com>
+ * gdb.base/ctf-ptype.c: Add struct link containing a forward
+ reference type.
+ * gdb.base/ctf-ptype.exp: Add "ptype struct link"
+
+2021-02-26 Weimin Pan <weimin.pan@oracle.com>
+
* gdb.base/ctf-ptype.exp: Add function tests and fix typos.
2021-02-26 Weimin Pan <weimin.pan@oracle.com>
diff --git a/gdb/testsuite/gdb.base/ctf-ptype.c b/gdb/testsuite/gdb.base/ctf-ptype.c
index cbc7815..51c7c68 100644
--- a/gdb/testsuite/gdb.base/ctf-ptype.c
+++ b/gdb/testsuite/gdb.base/ctf-ptype.c
@@ -124,6 +124,18 @@ struct {
a symbol. */
t_struct3 v_struct3;
+/**** Some misc more complicated things *******/
+
+struct link {
+ struct link *next;
+#ifdef __STDC__
+ struct link *(*linkfunc) (struct link *self, int flags);
+#else
+ struct link *(*linkfunc) ();
+#endif
+ struct t_struct stuff[3];
+} *s_link;
+
/**** unions *******/
union t_union {
diff --git a/gdb/testsuite/gdb.base/ctf-ptype.exp b/gdb/testsuite/gdb.base/ctf-ptype.exp
index 056f712..7dd6d95 100644
--- a/gdb/testsuite/gdb.base/ctf-ptype.exp
+++ b/gdb/testsuite/gdb.base/ctf-ptype.exp
@@ -76,6 +76,8 @@ if [gdb_test "ptype v_t_struct_p->v_float_member" "type = float"]<0 then {
return -1
}
+gdb_test "ptype struct link" "type = struct link \{\[\r\n\]+\[ \t\]+struct link \\*next;\[\r\n\]+\[ \t\]+struct link \\*\\(\\*linkfunc\\)\\((struct link \\*, int|void|)\\);\[\r\n\]+\[ \t\]+struct t_struct stuff.3.;\[\r\n\]+\}.*" "ptype linked list structure"
+
#
# test ptype command with unions
#
--
1.8.3.1
next prev parent reply other threads:[~2021-03-02 1:54 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-02 1:53 [PATCH,V2 0/5] CTF: bug fixes and new features Weimin Pan
2021-03-02 1:53 ` [PATCH,V2 1/5] CTF: fix incorrect function return type Weimin Pan
2021-03-02 1:53 ` [PATCH,V2 2/5] CTF: set up debug info for function arguments Weimin Pan
2021-03-02 1:53 ` Weimin Pan [this message]
2021-03-02 1:53 ` [PATCH,V2 4/5] CTF: add all members of an enum type to psymtab Weimin Pan
2021-03-02 1:53 ` [PATCH,V2 5/5] CTF: multi-CU and archive support Weimin Pan
2021-03-02 23:15 ` Lancelot SIX
2021-03-03 1:01 ` Wei-min Pan
2021-03-03 17:37 ` Lancelot SIX
2021-03-03 18:31 ` Weimin Pan
2021-03-03 20:46 ` [PATCH,V2 4/5] CTF: add all members of an enum type to psymtab Tom Tromey
2021-03-03 22:27 ` Wei-min Pan
2021-03-03 20:49 ` [PATCH,V2 3/5] CTF: handle forward reference type Tom Tromey
2021-03-03 22:01 ` Wei-min Pan
2021-03-02 12:23 ` [PATCH,V2 2/5] CTF: set up debug info for function arguments Lancelot SIX
2021-03-02 18:12 ` Wei-min Pan
2021-03-03 20:38 ` Tom Tromey
2021-03-03 21:58 ` Wei-min Pan
2021-03-03 20:41 ` Tom Tromey
2021-03-03 20:37 ` [PATCH,V2 1/5] CTF: fix incorrect function return type Tom Tromey
2021-03-03 21:57 ` Wei-min Pan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1614650018-9135-4-git-send-email-weimin.pan@oracle.com \
--to=weimin.pan@oracle.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).