🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gdb.bug
Article #1045

Re: Problem of GDB interaction with interrupted system calls

#1045
From: teawater
Date: Sun, 01 Nov 2009 08:51
112 lines
4517 bytes
This signal ctrl-c will not really send to inferior.

(gdb) help info handle

On Oct 31, 12:10 am, Alexandre Rusev <aru...@ru.mvista.com> wrote:
> Hi.
>
> When the program at ht end of message debugged under GDB is stopped with
> Ctrl+C
> it's usually found in interrupted system call. (The same result is
> observed for x86 and PPC with kernels 2.6.18 and 2.6.28)
>
> (gdb) where
> #0  0xb7fe2424 in __kernel_vsyscall ()
> #1  0xb7f36ad0 in nanosleep () from /lib/libc.so.6
> #2  0xb7f3690e in sleep () from /lib/libc.so.6
> #3  0x08048600 in qqq () at testBT2.c:45
> #4  0x080487a5 in eee () at testBT2.c:73
> #5  0x0804846a in main () at testBT2.c:17
>
> The PC is pointing at the next instruction, accordingly to GDB.
> But the kernel tries to restart syscall by means of changing PC to PC-4
> (in case of PowerPC and to some other value for x86)
> and it does it's change to PC after the user continues execution of
> program in GDB with "cont" or "si" command.
>
> The issue is that if user changed PC at this point or uses "call
> <func_name>" GDB command, the both changes to PC
> are added (as kernel uses PC relative change i.e. PC - 4), and the
> program continues execution at absolutely wrong place.
>
> The issue may be gracefully observed if breakpoint is set just before
> <func_name> and then PC is changed to the <func_name> address.
> In such case the breakpoint is hit while it must not be.
>
> #include <stdio.h>
> #include <stdlib.h>
>
> void qqq();
> void www();
> void eee();
>
> void * xrealloc(void*, int);
>
> int main(void)
> {
>         eee();
>     return EXIT_SUCCESS;
>
> }
>
> void qqq() {
>     void *a[256];
>     size_t i, n;
>
>     for (i = 0; i < 256; i++)
>     {
>         n = (size_t) ((rand() * 256.0) / (RAND_MAX + 1.0)) + 1;
>         a[i] = malloc(n);
>     }
>     for (i = 256; i > 0; i--)
>     {
>         n = (size_t) ((rand() * 256.0) / (RAND_MAX + 1.0)) + 1;
>         a[i - 1] = xrealloc(a[i - 1], n);
>     }
>     sleep(1);
>     for (i = 0; i < 256; i += 2)
>         free(a[i]);
>     for (i = 256; i > 0; i -= 2)
>         free(a[i - 1]);
>     sleep(1);
>
> }
>
> void www() {
>     void *a[256];
>     size_t i, n;
>
>     for (i = 0; i < 256; i++)
>     {
>         n = (size_t) ((rand() * 256.0) / (RAND_MAX + 1.0)) + 1;
>         a[i] = malloc(n);
>     }
>     for (i = 256; i > 0; i--)
>     {
>         n = (size_t) ((rand() * 256.0) / (RAND_MAX + 1.0)) + 1;
>         a[i - 1] = realloc(a[i - 1], n);
>     }
>     sleep(1);
>     for (i = 0; i < 256; i += 2)
>         free(a[i]);
>     for (i = 256; i > 0; i -= 2)
>         free(a[i - 1]);
>     sleep(1);
>
> }
>
> void eee() {
>
>         while (1) {
>                 qqq();
>
>                 www();
>
>         }
>
> }
>
> void * xrealloc(void* addr, int n) {
>         return realloc(addr, n);
>
> }
Technical Details
Message-ID: <19ff1afc-b27e-4715-a113-dde9929294bf@x25g2000prf.googlegroups.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!x25g2000prf.googlegroups.com!not-for-mail
References: <mailman.9741.1256919066.2239.bug-gdb@gnu.org>

Show Full Headers
Complete Article Headers
X-Google-Thread: f0ead4270c,ce66b84e91cebdde
X-Google-Attributes: gidf0ead4270c,public,usenet
X-Google-NewGroupId: yes
X-Google-Language: ENGLISH,ASCII
Path: arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!x25g2000prf.googlegroups.com!not-for-mail
From: teawater <teawater@gmail.com>
Newsgroups: gnu.gdb.bug
Subject: Re: Problem of GDB interaction with interrupted system calls
Date: Sun, 1 Nov 2009 01:51:10 -0700 (PDT)
Organization: http://groups.google.com
Lines: 113
Message-ID: <19ff1afc-b27e-4715-a113-dde9929294bf@x25g2000prf.googlegroups.com>
References: <mailman.9741.1256919066.2239.bug-gdb@gnu.org>
NNTP-Posting-Host: 123.117.167.122
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1257065471 11731 127.0.0.1 (1 Nov 2009 08:51:11 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Sun, 1 Nov 2009 08:51:11 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: x25g2000prf.googlegroups.com; posting-host=123.117.167.122; 
 posting-account=_rKHeQoAAACAAwOZJn9vt8H_tNKkLQZl
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1.3) 
 Gecko/20090824 Firefox/3.5.3,gzip(gfe),gzip(gfe)