[PATCH v2 2/7] Add "help news"

Simon Marchi simark@simark.ca
Mon Jul 6 14:14:20 GMT 2020


On 2020-07-05 11:59 a.m., Tom Tromey wrote:
>>>>>> "Christian" == Christian Biesinger via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Christian> On Tue, Jun 23, 2020 at 8:20 AM Tom Tromey <tom@tromey.com> wrote:
>>> +static void
>>> +help_news (struct ui_file *stream)
>>> +{
>>> +  std::string news_name = std::string (gdb_datadir) + SLASH_STRING + "NEWS";
>>> +  gdb_file_up news_file = gdb_fopen_cloexec (news_name.c_str (), "r");
>>> +  if (news_file == nullptr)
>>> +    perror_with_name (_("could not open the NEWS file"));
>>> +
>>> +  char buffer[1024];
>>> +  size_t offset = 0;
>>> +  while (true)
>>> +    {
>>> +      size_t nbytes = fread (&buffer[offset], 1, sizeof (buffer) - offset,
>>> +                            news_file.get ());
> 
> 
> Christian> Why not use read_entire_file from your other patch?
> 
> The NEWS file seems large-ish, and I figured the normal thing for users
> would be to use the pager to view the top, then stop reading.

The NEWS file is 281k and contains all NEWS since GDB 4.0 (pre year 2000).  So
I think it's safe to say that it grows much slower than the available memory
on the average computer grows.  That amount in memory is minimal compared to
what is typically used for reading DWARF information of large-ish programs,
and it's just transient use anyway.

So I think it's safe to read it all, and preferable if it makes the code
simpler.  I don't think reading 281k will cause any delay noticeable to the
user of "help news".

Simon


More information about the Gdb-patches mailing list