This is an archive of the discontinued LLVM Phabricator instance.

Fix a bug where lldb does not respect the packet size.
ClosedPublic

Authored by abidh on Jan 17 2017, 7:48 AM.

Details

Summary

LLDB was using packet size advertised by the target as the max memory size to write in one go. It is wrong because packets have other overhead apart from memory payload. Also memory transferred through 'm' and 'M' packets needs 2 bytes in packet to transfer 1 of memory.

Diff Detail

Event Timeline

abidh created this revision.Jan 17 2017, 7:48 AM
clayborg requested changes to this revision.Jan 17 2017, 9:33 AM

We need to check stub_max_size to make sure we don't get an integer underflow.

source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
3999

You need to check "sub_max_size" here. What if it says 64? We will then use a very large unsigned number UINT64_MAX - 6.

This revision now requires changes to proceed.Jan 17 2017, 9:33 AM
abidh updated this revision to Diff 84817.Jan 18 2017, 5:06 AM
abidh edited edge metadata.

Added the check to avoid integer underflow.

abidh added inline comments.Jan 18 2017, 5:13 AM
source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
3999

Thanks for review. I had a check in my development branch then removed it as the scenario seemed unlikely and there was not a good way to return error from this function. I was inclined to put this check in DoMemoryWrite/read and check the exact size every time but it looks overkill. The check added in this revision probably should be enough.

clayborg requested changes to this revision.Jan 18 2017, 8:50 AM

A few cleanups on the logging. See inlined comments.

source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
4004

We should use a GDB remote log channel instead of the LLDB channel. Since this is communication based I suggest:

Log *log(ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet(GDBR_LOG_COMM| GDBR_LOG_MEMORY));
4006–4007

Missing space between "small." and "LLDB". We should also warn once, not every time.

This revision now requires changes to proceed.Jan 18 2017, 8:50 AM
abidh updated this revision to Diff 84857.Jan 18 2017, 10:23 AM
abidh edited edge metadata.

Updated log calls as advised.

abidh marked 2 inline comments as done.Jan 18 2017, 10:26 AM
abidh added inline comments.
source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
4006–4007

This function has a check at the top so the packet size is checked only once.

abidh marked an inline comment as done.Jan 20 2017, 8:59 AM

Greg, any further comment on this patch.

clayborg requested changes to this revision.Jan 20 2017, 10:06 AM

See easy inline fix and this will be good to go

source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
4004

LogIfAny, not LogIfAll. Then either bit will work to show this.

This revision now requires changes to proceed.Jan 20 2017, 10:06 AM
abidh updated this revision to Diff 85280.Jan 22 2017, 10:13 AM
abidh edited edge metadata.

Use GetLogIfAnyCategoryIsSet as advised in comments.

abidh marked an inline comment as done.Jan 22 2017, 10:14 AM
clayborg accepted this revision.Jan 23 2017, 8:49 AM

Looks good.

This revision is now accepted and ready to land.Jan 23 2017, 8:49 AM
abidh closed this revision.Jan 24 2017, 3:06 PM