From patchwork Fri May 17 08:50:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Vidyadhar Kamath X-Patchwork-Id: 90359 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 511F4384AB42 for ; Fri, 17 May 2024 08:51:57 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by sourceware.org (Postfix) with ESMTPS id CC44B3858D20 for ; Fri, 17 May 2024 08:51:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CC44B3858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CC44B3858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::629 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715935891; cv=none; b=ln7bJnUj6zyXlf5rc61f+G1AcXWdLNBqGAeMqTTqX1Ey1KZcRGNLLUDyAevEf/ND8litNfdXyCcr1nnh/LGkFZygK2X1H56hT4pA5z8QH8OwqEan0Hef59X67mVK/Oaox3qdXcxvxfcix8BjD6g3kIdGuzxUE42+qvmzSzoLAHY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715935891; c=relaxed/simple; bh=KSsEBFPTzJk3PB/VPMcB7lG2ZtjgNLXVE8cTr73+T3g=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=wq1/EZEJkhPG/zUskod3RjcgqKN8HH8ojiMszJXJd3lUYj1594lTvJY/+RuVJAbJMpqqnc4fO4xVPvMb9kqgHN1WoyMpheywCWBhIvsaDGZzohf0hVxSNcLY+Ci18ZzvDxHQGHLuckB/TYdo4nF7T3lhO3KZOMuZaWYu1G3HG8M= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1ee7963db64so3394145ad.1 for ; Fri, 17 May 2024 01:51:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715935888; x=1716540688; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=nWx3DB6Da4MxppVBJ0LTqETXcbou2JX+jHTfAql8GFE=; b=Nn89Gat+Tkh4vaCOm44LBcTtHc0wc4zsOeAADstHpz4gFVeDdpEBJchbnVBa9kmTDc 3nIQ39OoA/+XIqDY1R7X88vNyAlX3hcjFe4h5x0x3Bh9Mw3OC1vLqcwuJG4FA2LBFOlM wA9rUmoxRZHBPnNkNO6DwXBZFzS0YoogdnW006HJr9Ik8loZpPBItSkNHCJrL+lXSlKH fszfItWHcoc7qirnmZRtPnK9/QjAWBY0MQxvY4w7mtYo6+YZf1tUZmlxJ2GmG3NfRBCz Pc0dEUrZAlRGqziJ35W/nK3Sty/K/nNJnM549tdruplpjIii0FI6tvRlQ73gZUmyHM0y Sj1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715935888; x=1716540688; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=nWx3DB6Da4MxppVBJ0LTqETXcbou2JX+jHTfAql8GFE=; b=xBv3qck5TAi1UE/rlJHTQEp/05MAvXoh/A6rVecaWjp3uLrFvGaT8pOCiOTT27ikUK a/DE4BiUjPKCrrJnUi/dkfvVIeQ5Fnw9aEvHFcHky9D+OThxd5o8KZr+K7ytxe5LGhkk sQF/9UxZo2J72v1rK6XWAZnPtffhMAyvJfhLtcP4mCZ55HJTLnKN4cWBTZwA3czS/05s LGRlbgji1F6YYgQLpWT2h++Q93EKMlHfbEwcqCj+/JoX9q/Q/HEJYNYcmUdAjRknH/Zn qoEgz0dpoibxuLpr9W37KI3RoCN7HEqTLsOXTPw1s1d/AOqmJGWkOV67P0vXVhifws31 Mv/Q== X-Forwarded-Encrypted: i=1; AJvYcCWHclc+rDTT84LmeraXlVH8kDx0uU4Nz33nx4VMGm01pXthLZ8Di+EzwdokfgehGXsLtJ8Ae9GeWT727jro9r+7cQhQhvETIIQzYw== X-Gm-Message-State: AOJu0YyDV80NikWMhHDd6/VSEbhQ1cqUawFALbH1sAgYGgiqsXkwSVxw iIZ2m8By2b9gPcvAuU4VWSosmprq3skDjCKvZ/SGYPpxPnsrEoj8 X-Google-Smtp-Source: AGHT+IHrhnQaZd0X5ZcWVQuPUrONoJcOXlahZT0W8VlcFeB7YaJ0J7b++BT5Og+80weKU1YGbmpcRA== X-Received: by 2002:a17:902:a514:b0:1ed:8d7c:d58e with SMTP id d9443c01a7336-1ef43e2836emr210549585ad.29.1715935887444; Fri, 17 May 2024 01:51:27 -0700 (PDT) Received: from localhost.localdomain ([2401:4900:1cb8:8c35:6cca:924e:fa39:e0a1]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0bad62bfsm152641615ad.74.2024.05.17.01.51.25 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 17 May 2024 01:51:26 -0700 (PDT) From: Aditya Vidyadhar Kamath To: tom@tromey.com Cc: ulrich.weigand@de.ibm.com, gdb-patches@sourceware.org, Aditya.Kamath1@ibm.com, sangamesh.swamy@in.ibm.com Subject: [PATCH] Contributing a thread fork testcase for AIX. Date: Fri, 17 May 2024 14:20:56 +0530 Message-Id: <20240517085055.95478-1-akamath996@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org From: Aditya Vidyadhar Kamath This test case tests if a child process created by a parent thread fork does not segment fault like in the commit https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=414aa6987f21a814851e5f3113388a3616993fa3 This test case also tests if the shared library is loaded properly for the child process. One example of why this is required is this commit https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=7a2a5ff865bead782393897fc5fde47def30dad4 where BFD file name for shared library members was changed when the library was loaded for the first time, which caused the library to no longer be recognized by name when loaded a second time. The test expects the GDB output to be as below in AIX: (gdb) set print thread-events on (gdb) set detach-on-fork off (gdb) set follow-fork-mode child (gdb) delete breakpoints (gdb) info breakpoints No breakpoints, watchpoints, tracepoints, or catchpoints. (gdb) break -qualified main Breakpoint 1 at 0x100009a8: file /current_gdb/binutils-gdb/gdb/testsuite/gdb.threads/thread_info_shared.c, line 65. (gdb) run Starting program: /current_gdb/binutils-gdb/gdb/testsuite/outputs/gdb.threads/thread_info_shared/thread_info_shared Breakpoint 1, main () at /current_gdb/binutils-gdb/gdb/testsuite/gdb.threads/thread_info_shared.c:65 65 alarm (300); (gdb) break Do_nothing Breakpoint 2 at 0x10000089c: file /current_gdb/binutils-gdb/gdb/testsuite/gdb.threads/thread_info_shared.c, line 32. (gdb) c Continuing. [New Thread 258 (tid 67438637)] [Attaching after Thread 258 (tid 67438637) fork to child process 14287164] [New inferior 2 (process 14287164)] Hello from Child! [Switching to Thread 258 (tid 68094177)] Thread 2.1 hit Breakpoint 2.2, Do_nothing () at /current_gdb/binutils-gdb/gdb/testsuite/gdb.threads/thread_info_shared.c:32 32 } (gdb) info sharedlibrary /usr/lib/libcrypt.a From To Syms Read Shared Object Library 0x0900000000695420 0x0900000000695c9e Yes (*) /usr/lib/libcrypt.a(shr_64.o) (*): Shared library is missing debugging information. (gdb) delete breakpoints Delete all breakpoints, watchpoints, tracepoints, and catchpoints? (y or n) y (gdb) info breakpoints No breakpoints, watchpoints, tracepoints, or catchpoints. (gdb) --- .../gdb.threads/thread_info_shared.c | 82 ++++++++++++++++++ .../gdb.threads/thread_info_shared.exp | 84 +++++++++++++++++++ 2 files changed, 166 insertions(+) create mode 100644 gdb/testsuite/gdb.threads/thread_info_shared.c create mode 100644 gdb/testsuite/gdb.threads/thread_info_shared.exp diff --git a/gdb/testsuite/gdb.threads/thread_info_shared.c b/gdb/testsuite/gdb.threads/thread_info_shared.c new file mode 100644 index 00000000000..a78f2ffb4e6 --- /dev/null +++ b/gdb/testsuite/gdb.threads/thread_info_shared.c @@ -0,0 +1,82 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2015-2023 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include +#include +#include +#include +#include + +pthread_barrier_t barrier; + +#define NUM_THREADS 1 + +void +Do_nothing () +{ + /* Does nothing. */ +} + +void * +thread_function (void *arg) +{ + /* This ensures that the breakpoint is only hit after both threads + are born. */ + pthread_barrier_wait (&barrier); + + pid_t p; + p = fork(); + if (p < 0) + { + perror("fork fail"); + exit(1); + } + // child process because return value zero + else if ( p == 0) + printf("Hello from Child!\n"); + + // parent process because return value non-zero. + else + printf("Hello from Parent!\n"); + + Do_nothing (); /* break here. */ +} + +int +main (void) +{ + int i; + + alarm (300); + + pthread_barrier_init (&barrier, NULL, NUM_THREADS); + + for (i = 0; i < NUM_THREADS; i++) + { + pthread_t thread; + int res; + + res = pthread_create (&thread, NULL, + thread_function, NULL); + assert (res == 0); + } + + while (1) + sleep (1); + + return 0; +} diff --git a/gdb/testsuite/gdb.threads/thread_info_shared.exp b/gdb/testsuite/gdb.threads/thread_info_shared.exp new file mode 100644 index 00000000000..94de4b1aca8 --- /dev/null +++ b/gdb/testsuite/gdb.threads/thread_info_shared.exp @@ -0,0 +1,84 @@ +# Copyright (C) 2007-2024 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# This file tests if thread fork event happens correctly when we follow +# and child's shared library is loaded correctly. + +# This test has been verified with AIX target, and would need +# to be generalized to support other targets + +require {is_any_target "*-*-aix*"} + +# When using the RSP, we don't get notifications about new threads. +# This is expected, so don't test for that. +if {[target_info gdb_protocol] == "remote" + || [target_info gdb_protocol] == "extended-remote"} { + return +} + +standard_testfile + +if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable debug] != "" } { + return -1 +} + +global srcdir subdir binfile srcfile + +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +gdb_test "set print thread-events on" + +gdb_test "set detach-on-fork off" +gdb_test "set follow-fork-mode child" + +if {![runto_main]} { + return 1 +} + +gdb_test "break Do_nothing" \ + "Breakpoint.*at.* file .*$srcfile, line.*" \ + "breakpoint at Do_nothing" + +set any "\[^\r\n\]*" + +# If the thread code is handled well we should not see any core dumps +# Or any different patterns here. + +gdb_test "c" \ + [multi_line \ + "\\\[New Thread $any\\\]" \ + "\\\[Attaching after Thread $any fork to child process $any\\\]" \ + "\\\[New inferior 2 $any\\\]" \ + "Hello from Child!" \ + "\\\[Switching to $any\\\]" \ + "$any" \ + "$any" \ + "$any" \ + ] \ + "Test for no seg fault after child is born." + +#Check if the shared library is loaded for child process. +# If shared library is not loaded correctly, this test will fail. +gdb_test "info sharedlibrary /usr/lib/libcrypt.a" \ + [multi_line \ + "From To Syms Read Shared Object Library" \ + "0x0900000000695420 0x0900000000695c9e Yes $any" \ + "\\\(\\\*\\\): Shared library is missing debugging information." \ + ] \ + "Test if child shared library is loaded" + +delete_breakpoints