Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add source context where available #9

Closed
bnagy opened this issue Sep 22, 2015 · 16 comments
Closed

Add source context where available #9

bnagy opened this issue Sep 22, 2015 · 16 comments
Assignees

Comments

@bnagy
Copy link

bnagy commented Sep 22, 2015

I love the gef commands, but when I have source I'd like to be able to see it...

gdb-dashboard shows source and asm if possible, just asm if not: https://github.com/cyrus-and/gdb-dashboard/blob/master/.gdbinit#L678-L752 which would be ideal...

@hugsy
Copy link
Owner

hugsy commented Sep 23, 2015

That's a pretty good idea. Will add that.

Thanks!

@hugsy hugsy self-assigned this Sep 23, 2015
hugsy pushed a commit that referenced this issue Sep 24, 2015
- context_source: #9 print dynamic symbol resolution
@hugsy
Copy link
Owner

hugsy commented Sep 24, 2015

It should be working as expected. Let me know if you find bugs.

img

@hugsy
Copy link
Owner

hugsy commented Sep 24, 2015

Confirmed works on x86, ARM, PowerPC for gdb > 7.9 (for gdb.find_pc_line())

@hugsy hugsy closed this as completed Sep 24, 2015
@bnagy
Copy link
Author

bnagy commented Sep 25, 2015

By >7.9 you mean it only works on 7.10? I re-enabled the exception printing and I get:

[!] in `context_source, exception raised: 'utf-8' codec can't decode byte 0xa9 in position 96: invalid start byte

ben@shitweasel:~/src/jxrlib$ gdb -version
GNU gdb (Ubuntu 7.9-1ubuntu1) 7.9

@hugsy hugsy reopened this Sep 25, 2015
@hugsy
Copy link
Owner

hugsy commented Sep 25, 2015

Which version of python are you using inside gdb ?

@bnagy
Copy link
Author

bnagy commented Sep 25, 2015

I don't know how to check that. System python is 2.7 but I thought gdb always links against 3 now? I'll google tomorrow :P

@bsmt
Copy link

bsmt commented Sep 25, 2015

Open a python shell in gdb ("pi" command), then

import sys
sys.version

@hugsy
Copy link
Owner

hugsy commented Sep 25, 2015

@bnagy $ gdb -nx -ex 'python print (sys.version)' -ex quit

@bnagy
Copy link
Author

bnagy commented Sep 26, 2015

'3.4.3 (default, Mar 26 2015, 22:07:14) \n[GCC 4.9.2]'

@hugsy
Copy link
Owner

hugsy commented Sep 27, 2015

I've setup an Ubuntu 14.04 with gdb 7.7 and python 3.4, could get your error triggered again.

Is it happening against all your bins ? Or just one ?

@bnagy
Copy link
Author

bnagy commented Sep 28, 2015

It's just one, by the looks - AND the source file happens to have a non-utf-8 character in the source file, so that sounds like a good chance to be the problem. I tried a quick guess from @bsmt using return buf.decode("utf-8", "ignore") in read_string but that didn't work - maybe I missed something or that's the wrong place to try and ignore bad UTF-8.....

@hugsy
Copy link
Owner

hugsy commented Sep 28, 2015

Do you have a sample somewhere I can download so I try to reproduce locally ?

@bnagy
Copy link
Author

bnagy commented Sep 29, 2015

Can't really, with this one... you should be able to put any non utf-8 char in the source though like from http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt

For now, I think I can run the codebase through iconv, which solves my immediate issue as per http://superuser.com/a/49147 (which is a possible workaround for anyone else with the issue, but hopefully it's easy to fix ;)

@hugsy
Copy link
Owner

hugsy commented Oct 9, 2015

Have you tried changing the charset (https://sourceware.org/gdb/onlinedocs/gdb/Character-Sets.html#Character-Sets) ? (set target-charset in gdb)

@bnagy
Copy link
Author

bnagy commented Oct 31, 2015

I tried set target-charset WINDOWS-1252 with no luck. Fixing the source files via iconv still works. If you can't work out a way to clean / change the encoding in the plugin then it's probably OK to close this issue, or just open a new one for the encoding problem (since the enhancement is complete)

Thanks again for the tool :)

PS: Inplace fixing didn't seem to work for me. This script does.

#! /bin/sh

find . -name '*.c' -exec iconv --verbose -f windows-1252 -t utf-8 -o {}.fix {} \;
find . -name "*.c" -delete
find . -name "*.c.fix" -exec rename 's/\.fix$//' {} \;

@hugsy
Copy link
Owner

hugsy commented Oct 31, 2015

I haven't been able to find a clean so I guess I will do as you suggest and close the ticket keeping in mind your little script in case this issue happens again in the future.

Thanks for the feedbacks, always appreciated :)

@hugsy hugsy closed this as completed Oct 31, 2015
SakiiR pushed a commit to SakiiR/gef that referenced this issue Jul 1, 2019
SakiiR pushed a commit to SakiiR/gef that referenced this issue Jul 1, 2019
- context_source: hugsy#9 print dynamic symbol resolution
SakiiR pushed a commit to SakiiR/gef that referenced this issue Jul 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants