From patchwork Sat May 18 19:13:49 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: 90410 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 3973C3858C39 for ; Sat, 18 May 2024 19:15:35 +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 959283858D20 for ; Sat, 18 May 2024 19:15:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 959283858D20 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 959283858D20 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=1716059711; cv=none; b=FHjIpq0qe/t0U+mX+ou9HDySEPt9eEA3+NTvwZtHTn13xxYaSlrvlHH+RQXfTwRnpgFx1/OEpDwOneE8x/rgphKmIfZEzm+B22jST2KEgItS4FtPfBY5s7R+3YDDlHF0d5j4CGC+X2ACf2wGxbJZw1U54+n/0oewdkt6eVs6rZw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716059711; c=relaxed/simple; bh=vHfmKPhgOm5wmQsPcQLfdrtBjBJeK/4HhEcoF6OeapE=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=A8hG/l8cB48w2Yq8jclaJ6v44YWTaJJ21OFsvUd7j/7/gI2GnOaNYK2h/59/6/gBSZExJRJECM8hUWAF9gMhuON90iS9SBthH1LMI04pE2SaaWhvV4Socr6eO3WCeno1CSHtteRf/9jRLM/4k/K4FDf8VpSlPInNf37jTI/8tAo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1edf506b216so39604405ad.2 for ; Sat, 18 May 2024 12:15:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716059708; x=1716664508; 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=htD1GFrIaTCcaLgSuK5V9cuHn53j+MqPks9HZYuUsis=; b=lvcAn5DIONGTfPXkfnx4Qs7uZQrQ4VzWrPfwZ1MmCR7stBdxX9Mo6GYq7w/ckRXgYe 56Ost1+Iat2wRv8kSx006GywTQa26oEYdYbwAzgbh14AbfL31nUm9BYYoKO4MwIBnRbW uru71zpA7Wym/gA7Vp51gZ8cgxCVlLLiLPSydcJeouS02cvaftzevf8xhYUCTw/5x8yC fg/B9Ew6KYPrezwOU2rQ6VFIwqHIH4rSCu8oKkij6CrWTOSI8x6k86v52r5KfdKRBe72 dwRU64zhz3DtDTb4Y5uIMfYB5b7tjXsd74MsXDlDMj6iUVQAy4J7hWS6tbLni56VfjnE tpog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716059708; x=1716664508; 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=htD1GFrIaTCcaLgSuK5V9cuHn53j+MqPks9HZYuUsis=; b=MqiNbuyj1MFnlmoBdXpAXVhrKHDOe6g1ryJw+qfPAVC7m2d1UIrJcn7bnCiCT70I5W eKaaOtV9sJe5oUCbXKtNYnqdbRMy/+BGu4g0KJhMiLr26aH5rziRmigXAIyV0gtEVagr tf6dZoRu5gES5lWl9Mxoomna6dzgeSI5w2r4exeKpR/xKSYBIQxxJlmj3AkBa6t+OyPF PxwHncloOVw4JWvxcDmBVa/1l9yR2iN9/+li2Hsv6dlId8olj2XgUP+xCbeSYEv52N5Q xgMBhiJMWSwie9GrpGw9cVHC3hkOzRSXC2BCrW0lncmTyvAAyR+0d+CTB0ZLom5E/CHk 3TRw== X-Forwarded-Encrypted: i=1; AJvYcCVugys+h1cuKoHYW7sAfHizcmRNfxOouIno2TqpJLINUJlZMKOwxhRz3LTDxaZBs+txJjtEmO6L0izJE41C0rnl+sqX4jKd0vI1MA== X-Gm-Message-State: AOJu0YwLL0GgmHkjOqGIe6ApgQHR1YUfcc8iD/qo/O7AE1S05M9fMdDp I90tq50txzvS5SZEwqQZoCsf3UbCbysSV8KfEyZSQKd1HWVtpW+vd1+7Vne9 X-Google-Smtp-Source: AGHT+IGs/53+sB5k5nGntnkrLkvUX6McvNYPjdmM5R1dAEiTFxyBYp3x8VQubvTGcYimqmO1kU5rZw== X-Received: by 2002:a17:902:728c:b0:1ec:31f5:16d5 with SMTP id d9443c01a7336-1ef43f2c758mr198422815ad.33.1716059708319; Sat, 18 May 2024 12:15:08 -0700 (PDT) Received: from localhost.localdomain ([2401:4900:1cb8:8c35:752d:d8a5:8b2e:109b]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0bf30c6fsm177256205ad.156.2024.05.18.12.15.06 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 18 May 2024 12:15:07 -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 v2] [RFC] Contributing a thread fork testcase for AIX. Date: Sun, 19 May 2024 00:43:49 +0530 Message-Id: <20240518191348.17752-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, 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 | 65 +++++++++++++++++ .../gdb.threads/thread_info_shared.exp | 72 +++++++++++++++++++ 2 files changed, 137 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..579e5b9d537 --- /dev/null +++ b/gdb/testsuite/gdb.threads/thread_info_shared.c @@ -0,0 +1,65 @@ +#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..4adb1320919 --- /dev/null +++ b/gdb/testsuite/gdb.threads/thread_info_shared.exp @@ -0,0 +1,72 @@ +# 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. +# Since /usr/lib/libcrypt.a will not be loaded and no address will be there +# And Syms Read will be No. + +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