Ticket #3817 (closed defect: fixed)

Opened 7 years ago

Last modified 7 years ago

[mcview] Library/executable symbols not fully viewable

Reported by: lastique Owned by: andrew_b
Priority: major Milestone: 4.8.20
Component: mcview Version: 4.8.18
Keywords: Cc: egmont
Blocked By: Blocking:
Branch state: merged Votes for changeset: committed-master

Description

When I press F3 on a library or executable with lots of exported symbols with long names (typical for C++ libraries), mcview does not always allow to scroll down though all symbols and stops halfway.

Steps to reproduce:

  1. Find an executable or library with lots of exported symbols with long names. For example, libboost_thread.so.1.62.0.
  1. Open it for viewing by pressing F3.
  1. Scroll down through symbols by pressing Arrow Down or Page Down key.
  1. At some point mcview stops scrolling as if the list of symbols ended. Typically this happens when the last symbol is very long (maybe longer than the console width; I don't know the exact criteria).
  1. At this point, if you scroll right by pressing Arrow Right or Ctrl+Arrow Right so that the viewer shows _past_ the end of the last symbol name, mcview allows to continue scrolling down by pressing Arrow Down or Page Down - until the next such point where it stops.

This bug is really annoying because one can't tell if the file has ended or not.

Attachments

mc-3817-mcview-eol.patch (2.5 KB) - added by egmont 7 years ago.
Fix

Change History

comment:1 in reply to: ↑ description Changed 7 years ago by andrew_b

Replying to lastique:

  1. At some point mcview stops scrolling as if the list of symbols ended. Typically this happens when the last symbol is very long (maybe longer than the console width; I don't know the exact criteria).

The exact criteria is 8K bytes. You can see that in the top-right corner as 8192/8192+.

comment:2 Changed 7 years ago by andrew_b

  • Cc egmont added

This behavior is not occured in text wrap mode.

I think the problem is in mcview_display_line (src/viewer/ascii.c:593) which is called in mcview_ascii_move_down (src/viewer/ascii.c:936). Probably, we should call mcview_may_still_grow() in ascii.c:593.

Egmont, do you have any idea?

comment:3 Changed 7 years ago by egmont

Will take a look soon, hopefully tonight. Thanks for looping me in! I could reproduce the problem. Do we know if it was my big rewrite that broke it? I'll check it.

I sometimes had a feeling that search was not reading the entire output, but, my bad, never cared enough to track down and file a bugreport. Could be caused by the same issue.

comment:4 Changed 7 years ago by egmont

It was indeed broken by me with the big viewer rewrite (#3250, bcb09f6).

comment:5 follow-up: ↓ 6 Changed 7 years ago by egmont

Trying to understand what's going on, to come up with the right fix:

mcview_display_line() contains two branches commented as "Optimization: Fast forward to the end of the line, rather than carefully parsing and then not actually displaying it."

This method does not only display the requested row of the screen, but also updates the state from where the next visible row can be painted. The state contains file offset, plus other attributes (e.g. nroff color) that we might need to carry.

In wrap mode, we need to stop right after displaying the visible row, there we have the state from where displaying the next visible row will continue. There's nothing else to do.

In nowrap mode, we need to skip to the end of the file's line. This is what the optimization branches do. This optimization could be cut off, in that case the "normal" body of the method would walk through the characters one by one, adjusting the state machine (e.g. tracking nroff changes etc.), just to drop this whole thing at the end (since no formatting state is carried across newlines).

A workaround for the current problem is to disable the ~10 lines of code at the top of this method commented as "Optimization....".

The core of the problem is that the "normal" path calls mcview_next_combining_char_sequence() which eventually uses mcview_get_byte() or mcview_get_utf() which take care of extending the growbuf if necessary. The shortcut optimized path calls mcview_eol() instead which does not. In fact, eventually it also calls mcview_get_byte(), however, beforehand it explicitly bails out if the end of the current buffer is reached, without trying to grow it.

Hence I'm wondering if the correct solution would be to fix mcview_eol() to grow if necessary.

This might fix some other weird corner cases as well. E.g. when the actual viewer area is only a single row high and you press Ctrl+E to get to the end of that line. (The bug here would be more prominent if Ctrl+E right-aligned the last visible row rather than the first. Then I guess we could spot a bug with sane window sizes as well.)

andrew_b, what do you think, does this approach sound reasonable to you?

comment:6 in reply to: ↑ 5 Changed 7 years ago by andrew_b

Replying to egmont:

andrew_b, what do you think, does this approach sound reasonable to you?

Yes, it is reasonable for me, but I'm not so deeply in the viewer code.

comment:7 Changed 7 years ago by egmont

(Forget the paragraph about other bugs/corner cases, it was stupid.)

Last edited 7 years ago by egmont (previous) (diff)

Changed 7 years ago by egmont

Fix

comment:8 Changed 7 years ago by egmont

Could you guys please test this patch?

I haven't paid too much attention to possible side effects and haven't tested it thoroughly.

Also note that this patch does _not_ fix the search issue I've referred to, that seems to be a different bug. I've reported that as #3819.

comment:9 Changed 7 years ago by lastique

I patched the 4.8.18 that is shipped with my Ubuntu 17.04 and a quick test shows the problem is fixed. I'll keep using the patched version and see if there are any problems.

Thanks guys.

comment:10 Changed 7 years ago by andrew_b

  • Status changed from new to accepted
  • Owner set to andrew_b
  • Votes for changeset set to andrew_b
  • Branch state changed from no branch to on review
  • Milestone changed from Future Releases to 4.8.20

Branch: 3817_mcview_grow_buffer
changeset:8d25e94bd59cde4b534ce6136e2eeb37c26dbe7d

(I have some problem with correct commit comment.)

comment:11 Changed 7 years ago by andrew_b

  • Branch state changed from on review to approved

comment:12 Changed 7 years ago by andrew_b

  • Status changed from accepted to testing
  • Votes for changeset changed from andrew_b to committed-master
  • Resolution set to fixed
  • Branch state changed from approved to merged

comment:13 Changed 7 years ago by andrew_b

  • Status changed from testing to closed
Note: See TracTickets for help on using tickets.