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

The new instance of QEMU executed on the behalf of the forked process tries to run gdbserver on the same port as its parent. #2

Closed
cedric-vincent opened this issue Apr 29, 2012 · 2 comments

Comments

@cedric-vincent
Copy link
Contributor

Details: https://groups.google.com/forum/?fromgroups#!topic/proot_me/ev2rS7kma30

@cedric-vincent
Copy link
Contributor Author

For the record, here is how to reproduce the problem:

    host$ proot -Q 'qemu-arm -g 1234' /path/to/arm/rootfs
    # waiting for GDB client ... connected

    guest$ /usr/bin/echo "Hello world"
    bind: Address already in use
    qemu: could not open gdbserver on port 1234

@cedric-vincent
Copy link
Contributor Author

The following solution works with QEMU 1.0 and later only. First, ask
to each instance of QEMU to unset the QEMU_GDB environment variable:

    proot -Q 'qemu-arm -U QEMU_GDB' ...

Then, set this variable to the expected port number right before
executing the program you want to debug. For examples:

  • to debug the first process (parent):
    env QEMU_GDB=1234 proot -Q 'qemu-arm -U QEMU_GDB' ...
    # waiting for GDB client
  • to debug a process launched interactively (or in a script):
    host$ proot -Q 'qemu-arm -U QEMU_GDB' ...

    guest$ /usr/bin/echo "Hello world"
    Hello world

    guest$ env QEMU_GDB=1234 /usr/bin/echo "Hello world"
    # waiting for GDB client
  • to debug a child process: add a call to setenv() before the call
    to exec(). It's a bit intrusive in this case but it's a reliable
    solution.

It works because QEMU 1.0+ handles options passed through environment
variable before command-line options, thus QEMU_GDB is unset after
being used by QEMU itself. Finally, only the first QEMU instance that
sees this variable is affected. Note that it works with any QEMU
options (see qemu-arm -h).

cedric-vincent added a commit that referenced this issue Jul 19, 2013
…ixed-size buffer.

  >>> CID 1047028 (#2 of 3): Copy into fixed size buffer (STRING_OVERFLOW)

  >>> 19. fixed_size_dest: You might overrun the 4096 byte fixed-size
  >>> string "scratch_path" by copying "guest_path" without checking the
  >>> length.

  >>> 20. parameter_as_source: Note: This defect has an elevated risk
  >>> because the source argument is a parameter of the current
  >>> function.

  258                        strcpy(scratch_path, guest_path);
cedric-vincent added a commit that referenced this issue Jul 19, 2013
…ed-size buffer.

  >>> CID 1047027 (#1 of 2): Copy into fixed size buffer (STRING_OVERFLOW)

  >>> 15. fixed_size_dest: You might overrun the 4096 byte fixed-size
  >>> string "binding->host.path" by copying "tracee->glue" without
  >>> checking the length.

  >>> 16. parameter_as_source: Note: This defect has an elevated risk
  >>> because the source argument is a parameter of the current
  >>> function.

158        strcpy(binding->host.path, tracee->glue);

  >>> CID 1047027 (#2 of 2): Copy into fixed size buffer (STRING_OVERFLOW)

159        strcpy(binding->guest.path, guest_path);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant