fprintf: Fixup the printing of const parameters

The last problem with 'pfunct --compile' at least for tcp.o:

Before:

  $ pfunct --compile examples/tcp.o > tcp.pahole.c
  $ gcc -c tcp.pahole.c -g
  tcp.pahole.c:1808:48: error: unknown type name ‘u8const’; did you mean ‘const’?
   inline void tcp_set_ca_state(struct sock * sk, u8const ca_state)
                                                  ^~~~~~~
                                                  const
  tcp.pahole.c:5346:56: error: unknown type name ‘intconst’; did you mean ‘const’?
   inline void skb_set_tail_pointer(struct sk_buff * skb, intconst offset)
                                                          ^~~~~~~~
                                                          const
  tcp.pahole.c:5914:37: error: unknown type name ‘gfp_tconst’; did you mean ‘gfp_t’?
   inline bool gfpflags_allow_blocking(gfp_tconst gfp_flags)
                                       ^~~~~~~~~~
                                       gfp_t
  tcp.pahole.c:5926:24: error: unknown type name ‘ktime_tconst’; did you mean ‘ktime_t’?
   inline s64 ktime_to_ns(ktime_tconst kt)
                          ^~~~~~~~~~~~
                          ktime_t
  tcp.pahole.c:5939:54: warning: ‘struct timespec64const’ declared inside parameter list will not be visible outside of this definition or declaration
   inline struct timespec timespec64_to_timespec(struct timespec64const ts64)
                                                        ^~~~~~~~~~~~~~~
  tcp.pahole.c:5939:70: error: parameter 1 (‘ts64’) has incomplete type
   inline struct timespec timespec64_to_timespec(struct timespec64const ts64)
                                                 ~~~~~~~~~~~~~~~~~~~~~~~^~~~
  $

After:

  $ pfunct --compile examples/tcp.o > tcp.pahole.c
  $ gcc -c tcp.pahole.c -g

Because:

  $ grep -A2 tcp_set_ca_state tcp.pahole.c
  inline void tcp_set_ca_state(struct sock * sk, const u8 ca_state)
  {
  }
  $

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2019-04-04 21:47:36 -03:00
parent 7aec7dd6c2
commit ce6f393bc9
1 changed files with 4 additions and 6 deletions

View File

@ -498,7 +498,7 @@ static const char *__tag__name(const struct tag *tag, const struct cu *cu,
const char *tag__name(const struct tag *tag, const struct cu *cu,
char *bf, size_t len, const struct conf_fprintf *conf)
{
bool starts_with_const = false;
int printed = 0;
if (tag == NULL) {
strncpy(bf, "void", len);
@ -506,14 +506,12 @@ const char *tag__name(const struct tag *tag, const struct cu *cu,
}
if (tag->tag == DW_TAG_const_type) {
starts_with_const = true;
snprintf(bf, len, "%s ", "const");
printed = strlen(bf);
tag = cu__type(cu, tag->type);
}
__tag__name(tag, cu, bf, len, conf);
if (starts_with_const)
strncat(bf, "const", len);
__tag__name(tag, cu, bf + printed, len - printed, conf);
return bf;
}