gdb.setup:4: Error in sourced command file:

3,546 views
Skip to first unread message

omara...@gmail.com

unread,
May 23, 2010, 1:50:58 PM5/23/10
to android-ndk
Hi,

I am not able to start a debug session. I was trying to debug the
sample hello-jni, but I get an error message "gdb.setup:4: Error in
sourced command file:", "Remote communication error: Connection reset
by peer". I followed all the steps for building and made sure all
conditions in NDK-GDB.TXT are met. I hope someone can help.

Thanks,
Omar

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.

David Turner

unread,
May 23, 2010, 6:24:41 PM5/23/10
to andro...@googlegroups.com
"Connection rest by peer" indicates a problem when trying to gdbserver running on the device/emulator.
The most likely problem is that your process crashed before gdbserver could attach to it.

omara...@gmail.com

unread,
May 24, 2010, 9:39:01 AM5/24/10
to android-ndk

Thank you David for the help. The process didn't crash and the
emulator is displaying "Hello from JNI !". Here is what I get at the
log:

DEBUG/AndroidRuntime(269): >>>>>>>>>>>>>> AndroidRuntime START
<<<<<<<<<<<<<<
DEBUG/AndroidRuntime(269): CheckJNI is ON
DEBUG/AndroidRuntime(269): --- registering native functions ---
INFO/ActivityManager(58): Starting activity: Intent { flg=0x10000000
cmp=com.example.hellojni/.HelloJni }
DEBUG/AndroidRuntime(269): Shutting down VM
DEBUG/dalvikvm(269): Debugger has detached; object registry had 1
entries
INFO/ActivityManager(58): Start proc com.example.hellojni for activity
com.example.hellojni/.HelloJni: pid=276 uid=10031 gids={1015}
INFO/AndroidRuntime(269): NOTE: attach of thread 'Binder Thread #3'
failed
DEBUG/dalvikvm(276): Trying to load lib /data/data/
com.example.hellojni/lib/libhello-jni.so 0x43dc2970
DEBUG/dalvikvm(276): Added shared lib /data/data/com.example.hellojni/
lib/libhello-jni.so 0x43dc2970
DEBUG/dalvikvm(276): No JNI_OnLoad found in /data/data/
com.example.hellojni/lib/libhello-jni.so 0x43dc2970, skipping init
INFO/ActivityManager(58): Displayed activity
com.example.hellojni/.HelloJni: 823 ms (total 823 ms)
DEBUG/dalvikvm(122): GC_EXPLICIT freed 11891 objects / 598608 bytes in
108ms

I hope this helps.

Thanks,
Omar

On May 24, 1:24 am, David Turner <di...@android.com> wrote:
> "Connection rest by peer" indicates a problem when trying to gdbserver
> running on the device/emulator.
> The most likely problem is that your process crashed before gdbserver could
> attach to it.
>
> On Sun, May 23, 2010 at 10:50 AM, omarash...@gmail.com <omarash...@gmail.com
>
>
>
> > wrote:
> > Hi,
>
> > I am not able to start a debug session. I was trying to debug the
> > sample hello-jni, but I get an error message "gdb.setup:4: Error in
> > sourced command file:", "Remote communication error: Connection reset
> > by peer". I followed all the steps for building and made sure all
> > conditions in NDK-GDB.TXT are met. I hope someone can help.
>
> > Thanks,
> > Omar
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "android-ndk" group.
> > To post to this group, send email to andro...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > android-ndk...@googlegroups.com<android-ndk%2Bunsu...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/android-ndk?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups "android-ndk" group.
> To post to this group, send email to andro...@googlegroups.com.
> To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/android-ndk?hl=en.

niko20

unread,
May 24, 2010, 10:14:35 AM5/24/10
to android-ndk
These are the exact error messages I get

I'm using Windows with Cygwin

One in a while it will connect without this error.

I also get errors about some file called "app_process" - I ran ndk-gdb
in verbose mode and it says it's trying to copy something /system/bin/
app_process to my local /cygwin/c/workspace/reloop/jni/local or
whatever, and it says the file was not found.

Also, I seem to not have any "source" - if I type "list" for example,
it shows me nothing. It tells me no symbol tables are loaded. I'm not
sure how do I get symbols loaded..so I cant seem to set breakpoints at
all.

Also, how would you set a breakpoint if you need one at "startup" -
for example if the app calls a native function while its starting. GDB
doesn't seem to connect until a little while after the program is
already running...

-niko



On May 24, 8:39 am, "omarash...@gmail.com" <omarash...@gmail.com>
wrote:
> > > android-ndk...@googlegroups.com<android-ndk%2Bunsubscribe@googlegr oups.com>

niko20

unread,
May 25, 2010, 8:42:16 AM5/25/10
to android-ndk
Hi,

I found that if you get this error you can still reconnect by simply
typing in "target remote:<port>" in gdb (put in the port number that
it's using the talk to gdbserver)

It must be a timing issue where gdb tries to connect but something
isnt ready. On my work machine it never does this, but on my home
machine it does it a lot, but not always. My home machine is way
faster.


-niko

omara...@gmail.com

unread,
May 27, 2010, 5:25:37 AM5/27/10
to android-ndk

Niko,

Thank you for the help. I found the problem. I was getting an error
"awk: /home/omar/bin/build/awk/extract-pid.awk: line 47: function
gensub never defined". It seems I missed the awk package part in
"Required development tools" in http://developer.android.com/sdk/ndk/index.html.
I used "sudo apt-get install gawk" to install it.

Thanks,
Omar

gymshoe

unread,
Jun 3, 2010, 11:26:13 PM6/3/10
to android-ndk
I am glad you got your problem solved, but the solution does not make
sense and doesn't resolve my issue.

If you were getting the error "awk: /home/..../extract-pid.awk: line
47: function gensub never defined", isn't this an error coming from
awk itself???
If it wasn't coming from awk, how did it get through the first 46
lines of extract-pid.awk?

The reason I ask is because I am getting the same issue (although mine
reads:
"awk: calling undefined function gensub
source line number 33" ) when I try to run the ndk-gdb command,
and I clearly do have awk installed (ver20070501) which seems "recent"
to me. Does anyone know how recent is "recent" in the android
requirements stating "recent" awk?

Any help appreciated.

Jim





On May 27, 3:25 am, "omarash...@gmail.com" <omarash...@gmail.com>
wrote:
> Niko,
>
> Thank you for the help. I found the problem. I was getting an error
> "awk: /home/omar/bin/build/awk/extract-pid.awk: line 47: function
> gensub never defined". It seems I missed the awk package part in
> "Required development tools" inhttp://developer.android.com/sdk/ndk/index.html.
> I used "sudo apt-get install gawk" to install it.
>
> Thanks,
> Omar
>
> On May 25, 3:42 pm, niko20 <nikolatesl...@yahoo.com> wrote:
>
>
>
> > Hi,
>
> > I found that if you get this error you can still reconnect by simply
> > typing in "target remote:<port>" ingdb(put in the port number that
> > it's using the talk to gdbserver)
>
> > It must be a timing issue wheregdbtries to connect but something

David Turner

unread,
Jun 3, 2010, 11:29:47 PM6/3/10
to andro...@googlegroups.com
yes, this error comes from OS X BSD awk not supporting "gensub".
I'm preparing a bugfix release for r4 that will deal with this and other annoying stuff.

In the meantime, you can try using HOST_AWK=gawk when invoking ndk-gdb,
where 'gawk' is GNU Awk (installed through MacPorts, for example)

sorry about that.

gymshoe

unread,
Jun 3, 2010, 11:46:39 PM6/3/10
to android-ndk
Excellent!, this has been driving me craezzzzzzzy!
I will try to download GNU Awk.

thnks,
Jim

Mike v

unread,
Jun 10, 2010, 12:11:14 PM6/10/10
to android-ndk
Many thanks for this message David, i've seen the "gensub" message and
now it is at least clear where the problem is

greets
mike

Mike v

unread,
Jun 10, 2010, 12:47:19 PM6/10/10
to android-ndk

> "awk: /home/omar/bin/build/awk/extract-pid.awk: line 47: function
> gensub never defined". It seems I missed the awk package part in
> "Required development tools" inhttp://developer.android.com/sdk/ndk/index.html.
> I used "sudo apt-get install gawk" to install it.

I've just installed gawk on Mac/Snow Leopard with "sudo port install
gawk" and changed awk to gawk in ndk-gdb

everything goes well, though lib/gdbserver cannot attach the the
desired process:

<<<
/Users/mike_vasiljevs/development/android/android-sdk-mac_86/tools/adb
shell run-as com.example.hellonjni lib/gdbserver +debug-socket --
attach 618
##### NEW COMMAND
adb pull /system/bin/app_process /Users/mike_vasiljevs/development/
android/android-ndk-r4-crystax/samples/hello-jni/bin/ndk/local/armeabi/
app_process
372 KB/s (5676 bytes in 0.014s)
Pulled from device/emulator.
Cannot attach to process 618: Operation not permitted (1)
>>>

i tried to forward ports manually and then running gdbserver again on
the device, and it fails also
"run-as com.example.hellonjni lib/gdbserver :5039 --attach 618"


would be nice to hear opinions on that...

greets
mike

>
> Thanks,
> Omar
>
> On May 25, 3:42 pm, niko20 <nikolatesl...@yahoo.com> wrote:
>
>
>
> > Hi,
>
> > I found that if you get thiserroryou can still reconnect by simply
> > typing in "targetremote:<port>" in gdb (put in the port number that
> > it's using the talk to gdbserver)
>
> > It must be a timing issue where gdb tries to connect but something
> > isnt ready. On my work machine it never does this, but on my home
> > machine it does it a lot, but not always. My home machine is way
> > faster.
>
> > -niko
>
> > On May 24, 9:14 am, niko20 <nikolatesl...@yahoo.com> wrote:
>
> > > These are the exacterrormessages I get
> > > > > "Connectionrest bypeer" indicates a problem when trying to gdbserver
> > > > > running on the device/emulator.
> > > > > The most likely problem is that your process crashed before gdbserver could
> > > > > attach to it.
>
> > > > > On Sun, May 23, 2010 at 10:50 AM, omarash...@gmail.com <omarash...@gmail.com
>
> > > > > > wrote:
> > > > > > Hi,
>
> > > > > > I am not able to start a debug session. I was trying to debug the
> > > > > > sample hello-jni, but I get anerrormessage "gdb.setup:4:Errorin
> > > > > > sourced command file:", "Remotecommunicationerror:Connectionreset
> > > > > > bypeer". I followed all the steps for building and made sure all

Mike v

unread,
Jun 10, 2010, 12:55:31 PM6/10/10
to android-ndk
...also regarding to first set of posts i am just using the hellojni
example - just added the while(1) {} loop to the code;

David Turner

unread,
Jun 10, 2010, 3:09:45 PM6/10/10
to andro...@googlegroups.com
On Thu, Jun 10, 2010 at 9:47 AM, Mike v <mike.va...@gmail.com> wrote:

<<<
/Users/mike_vasiljevs/development/android/android-sdk-mac_86/tools/adb
shell run-as com.example.hellonjni lib/gdbserver +debug-socket --
attach 618
##### NEW COMMAND
adb pull /system/bin/app_process /Users/mike_vasiljevs/development/
android/android-ndk-r4-crystax/samples/hello-jni/bin/ndk/local/armeabi/
app_process
372 KB/s (5676 bytes in 0.014s)
Pulled  from device/emulator.
Cannot attach to process 618: Operation not permitted (1)
>>>

Wow, this is so weird. Can you tell me the exact size and md5sum of the gdbserver binary that must be
located under your $PROJECT/libs/armeabi (or $PROJECTS/libs/armeabi-v7a) ? I suspect this is not
the correct version (and well, you're using the crystax NDK, so I need to check this before anything else).

Dmitry Moskalchuk

unread,
Jun 10, 2010, 5:35:28 PM6/10/10
to andro...@googlegroups.com
Hi David,

Is it so important? Of course, gdbserver binary in my distribution has another size and md5sum than in original one. But I've tried it with emulator (2.2) on Snow Leopard and have no such problems. I looked it headers using command 'arm-eabi-objdump -x gdbserver' and compare them with the headers from original one. The only difference is actual addresses of sections.

Just for the record: size of gdbserver binary in my distribution is 111724 bytes and its md5sum is 0e8b4bda83c19dd471c4504c87dc8270.

Dmitry Moskalchuk

10.06.2010 23:09, David Turner пишет:

David Turner

unread,
Jun 10, 2010, 6:10:09 PM6/10/10
to andro...@googlegroups.com
On Thu, Jun 10, 2010 at 2:35 PM, Dmitry Moskalchuk <cry...@gmail.com> wrote:
Hi David,

Is it so important?

It depends, I have patched the gdbserver source code to allow it to attach to a Unix-domain socket, so it is important to ensure that
the binary you are using corresponds to this.
 
The error reported is quite weird: it essentially says that gdbserver tried a ptrace_attach() that failed. This can only happen if you
are not trying to attach to a running process that was launched under the same user id.

I also notice something strange about your log:

shell run-as com.example.hellonjni lib/gdbserver +debug-socket --attach 618

this "hellonjni" should be "hellojni", it looks like you're trying to attach to the wrong process. Did you do anything extraordinary
with the files generated by ndk-build before packaging your application ? Can you send the complete ndk-gdb --verbose log ?

Dmitry Moskalchuk

unread,
Jun 10, 2010, 6:26:43 PM6/10/10
to andro...@googlegroups.com
Well, this is not my log and not my problem - I've running it without problems. And yes, gdbserver used in crystax ndk include this patch - it is built from the same sources as original one. No modifications.

Looking to the Mike's log, it's very likely files in NDK were changed in some inconsistent way after unpack. What I suggest to solve the problem is:
1. Unpack fresh distribution
2. Edit ndk-gdb: a) change 'AWK_CMD=awk' to 'AWK_CMD=gawk' and b) change "sed -e 's!\\r!!g'" to "sed -e 's![[:cntrl:]]!!g'" (three places)
3. Go to samples/hello-jni and try again (ndk-build, android update project, ant install, ndk-gdb).

Doing this steps I have hello-jni application working and debuggable on emulator under Snow Leopard.


Dmitry Moskalchuk

11.06.2010, в 2:10, David Turner написал(а):
Reply all
Reply to author
Forward
0 new messages