Skip to content
This repository was archived by the owner on Sep 12, 2025. It is now read-only.

Commit d50af03

Browse files
authored
Add script to analyze core dumps with gdb (#10)
Introduces analyze_core_dumps.sh to automate core dump analysis using GDB. The script provides stack traces and register information for analyzing crashes in executables, with particular focus on Postgres/Cloudberry. Features: - Automatic core dump detection and analysis - Detailed stack traces and register info via GDB - Comprehensive logging of analysis results - Dependency checking for required tools - Clear return codes for automation: 0: No cores found 1: Cores processed successfully 2: Errors (missing deps or processing failures) The script is designed to integrate with automated testing and CI/CD pipelines while also being useful for manual debugging sessions. Add conditional debug build support to configure Modifies configure script to optionally enable debug-related compile options: - --enable-debug - --enable-profiling - --enable-cassert - --enable-debug-extensions These flags are enabled when ENABLE_DEBUG=true is set in the environment. This provides flexibility to generate both debug and non-debug builds from the same script, defaulting to non-debug builds.
1 parent 54bbb3d commit d50af03

File tree

5 files changed

+279
-28
lines changed

5 files changed

+279
-28
lines changed
Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
#!/bin/bash
2+
# --------------------------------------------------------------------
3+
#
4+
# Licensed to the Apache Software Foundation (ASF) under one or more
5+
# contributor license agreements. See the NOTICE file distributed
6+
# with this work for additional information regarding copyright
7+
# ownership. The ASF licenses this file to You under the Apache
8+
# License, Version 2.0 (the "License"); you may not use this file
9+
# except in compliance with the License. You may obtain a copy of the
10+
# License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17+
# implied. See the License for the specific language governing
18+
# permissions and limitations under the License.
19+
#
20+
# --------------------------------------------------------------------
21+
#
22+
# Script: analyze_core_dumps.sh
23+
# Description: Automated analysis tool for core dump files using GDB
24+
#
25+
# This script automatically analyzes core dump files found in a
26+
# specified directory, providing stack traces and register
27+
# information. It's particularly useful for analyzing crashes in
28+
# Postgres/Cloudberry executables and Python applications.
29+
#
30+
# Features:
31+
# - Automatic detection of core dump files
32+
# - Support for both compiled executables and interpreted languages
33+
# - Detailed stack traces with GDB
34+
# - Register state analysis
35+
# - Assembly code context at crash point
36+
# - Comprehensive logging of analysis results
37+
#
38+
# Usage: analyze_core_dumps.sh [test_id]
39+
# test_id: Optional identifier for the test configuration that generated cores
40+
#
41+
# Dependencies:
42+
# - GDB (GNU Debugger)
43+
# - file command
44+
#
45+
# Environment Variables:
46+
# SRC_DIR - Base directory for operations (defaults to /tmp)
47+
#
48+
# Return Codes:
49+
# 0 - No core files were found
50+
# 1 - Core files were found and all were processed successfully
51+
# 2 - Error conditions:
52+
# - Missing required dependencies (gdb, file)
53+
# - Issues processing some or all core files
54+
# --------------------------------------------------------------------
55+
56+
set -u
57+
58+
# Configuration
59+
#-----------------------------------------------------------------------------
60+
# Use SRC_DIR if defined, otherwise default to /tmp
61+
SRC_DIR="${SRC_DIR:-/tmp}"
62+
# Define log directory and files
63+
LOG_DIR="${SRC_DIR}/build-logs"
64+
# Create log directories if they don't exist
65+
mkdir -p "${LOG_DIR}"
66+
67+
# Determine log file name based on test_id argument
68+
if [ $# -ge 1 ]; then
69+
test_id="$1"
70+
log_file="${LOG_DIR}/core_analysis_${test_id}_$(date +%Y%m%d_%H%M%S).log"
71+
else
72+
log_file="${LOG_DIR}/core_analysis_$(date +%Y%m%d_%H%M%S).log"
73+
fi
74+
echo "log_file: ${log_file}"
75+
76+
# Directory where core dumps are located
77+
core_dir="/tmp/cloudberry-cores/"
78+
79+
# Pattern to match core dump files
80+
core_pattern="core-*"
81+
82+
# Function Definitions
83+
#-----------------------------------------------------------------------------
84+
# Log messages to both console and log file
85+
# Args:
86+
# $1 - Message to log
87+
log_message() {
88+
local message="[$(date '+%Y-%m-%d %H:%M:%S')] $1"
89+
echo "$message"
90+
echo "$message" >> "$log_file"
91+
}
92+
93+
# Analyze a single core file
94+
# Args:
95+
# $1 - Path to core file
96+
# Returns:
97+
# 0 on success, 1 on failure
98+
analyze_core_file() {
99+
local core_file="$1"
100+
local file_info
101+
102+
log_message "Analyzing core file: $core_file"
103+
file_info=$(file "$core_file")
104+
log_message "Core file info: $file_info"
105+
106+
# Extract the original command from the core file info
107+
if [[ "$file_info" =~ "from '([^']+)'" ]]; then
108+
local original_cmd="${BASH_REMATCH[1]}"
109+
log_message "Original command: $original_cmd"
110+
fi
111+
112+
# Extract executable path from core file info
113+
if [[ "$file_info" =~ execfn:\ \'([^\']+)\' ]]; then
114+
local executable="${BASH_REMATCH[1]}"
115+
log_message "Executable path: $executable"
116+
117+
# Convert relative path to absolute if needed
118+
if [[ "$executable" == "./"* ]]; then
119+
executable="$PWD/${executable:2}"
120+
log_message "Converted to absolute path: $executable"
121+
fi
122+
123+
# Run GDB analysis
124+
log_message "Starting GDB analysis..."
125+
126+
gdb -quiet \
127+
--batch \
128+
-ex 'set pagination off' \
129+
-ex 'info target' \
130+
-ex 'thread apply all bt' \
131+
-ex 'print $_siginfo' \
132+
-ex quit \
133+
"$executable" "$core_file" 2>&1 >> "$log_file"
134+
135+
local gdb_rc=$?
136+
if [ $gdb_rc -eq 0 ] && [ -s "$log_file" ]; then
137+
log_message "GDB analysis completed successfully"
138+
return 0
139+
else
140+
log_message "Warning: GDB analysis failed or produced no output"
141+
return 1
142+
fi
143+
else
144+
log_message "Could not find executable path in core file"
145+
return 1
146+
fi
147+
}
148+
149+
# Function to check required commands
150+
check_dependencies() {
151+
local missing=0
152+
local required_commands=("gdb" "file")
153+
154+
log_message "Checking required commands..."
155+
for cmd in "${required_commands[@]}"; do
156+
if ! command -v "$cmd" >/dev/null 2>&1; then
157+
log_message "Error: Required command '$cmd' not found"
158+
missing=1
159+
fi
160+
done
161+
162+
if [ $missing -eq 1 ]; then
163+
log_message "Missing required dependencies. Please install them and try again."
164+
return 1
165+
fi
166+
167+
log_message "All required commands found"
168+
return 0
169+
}
170+
171+
# Main Execution
172+
#-----------------------------------------------------------------------------
173+
main() {
174+
local core_count=0
175+
local analyzed_count=0
176+
local return_code=0
177+
178+
log_message "Starting core dump analysis"
179+
log_message "Using source directory: $SRC_DIR"
180+
log_message "Using log directory: $LOG_DIR"
181+
182+
# Check dependencies first
183+
if ! check_dependencies; then
184+
return 2
185+
fi
186+
187+
# Process all core files
188+
for core_file in "$core_dir"/$core_pattern; do
189+
if [[ -f "$core_file" ]]; then
190+
((core_count++))
191+
if analyze_core_file "$core_file"; then
192+
((analyzed_count++))
193+
fi
194+
fi
195+
done
196+
197+
# Determine return code based on results
198+
if ((core_count == 0)); then
199+
log_message "No core files found matching pattern $core_pattern in $core_dir"
200+
return_code=0 # No cores found
201+
elif ((analyzed_count == core_count)); then
202+
log_message "Analysis complete. Successfully processed $analyzed_count core(s) files"
203+
return_code=1 # All cores processed successfully
204+
else
205+
log_message "Analysis complete with errors. Processed $analyzed_count of $core_count core files"
206+
return_code=2 # Some cores failed to process
207+
fi
208+
209+
log_message "Log file: $log_file"
210+
211+
return $return_code
212+
}
213+
214+
# Script entry point
215+
main
216+
return_code=$?
217+
218+
if ((return_code == 0)); then
219+
rm -fv "${log_file}"
220+
fi
221+
222+
exit $return_code

build_automation/cloudberry/scripts/configure-cloudberry.sh

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@
5151
#
5252
# Optional Environment Variables:
5353
# LOG_DIR - Directory for logs (defaults to ${SRC_DIR}/build-logs)
54+
# ENABLE_DEBUG - Enable debug build options (true/false, defaults to
55+
# false)
56+
#
57+
# When true, enables:
58+
# --enable-debug
59+
# --enable-profiling
60+
# --enable-cassert
61+
# --enable-debug-extensions
5462
#
5563
# Prerequisites:
5664
# - System dependencies must be installed:
@@ -106,19 +114,28 @@ log_section "Environment Setup"
106114
export LD_LIBRARY_PATH=/usr/local/cloudberry-db/lib:LD_LIBRARY_PATH
107115
log_section_end "Environment Setup"
108116

117+
# Add debug options if ENABLE_DEBUG is set to "true"
118+
CONFIGURE_DEBUG_OPTS=""
119+
120+
if [ "${ENABLE_DEBUG:-false}" = "true" ]; then
121+
CONFIGURE_DEBUG_OPTS="--enable-debug \
122+
--enable-profiling \
123+
--enable-cassert \
124+
--enable-debug-extensions"
125+
fi
126+
109127
# Configure build
110128
log_section "Configure"
111129
execute_cmd ./configure --prefix=/usr/local/cloudberry-db \
112130
--disable-external-fts \
113-
--enable-cassert \
114-
--enable-debug-extensions \
115131
--enable-gpcloud \
116132
--enable-ic-proxy \
117133
--enable-mapreduce \
118134
--enable-orafce \
119135
--enable-orca \
120136
--enable-pxf \
121137
--enable-tap-tests \
138+
${CONFIGURE_DEBUG_OPTS} \
122139
--with-gssapi \
123140
--with-ldap \
124141
--with-libxml \

build_automation/cloudberry/scripts/parse-test-results.sh

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -96,23 +96,5 @@ if [ ! -f test_results.txt ]; then
9696
exit 2
9797
fi
9898

99-
source test_results.txt
100-
101-
# If in GitHub Actions, set outputs
102-
if [ -n "${GITHUB_OUTPUT:-}" ]; then
103-
{
104-
echo "status=$STATUS"
105-
echo "total_tests=$TOTAL_TESTS"
106-
echo "failed_tests=$FAILED_TESTS"
107-
echo "passed_tests=$PASSED_TESTS"
108-
echo "ignored_tests=$IGNORED_TESTS"
109-
[ -n "${FAILED_TEST_NAMES:-}" ] && echo "failed_test_names=$FAILED_TEST_NAMES"
110-
[ -n "${IGNORED_TEST_NAMES:-}" ] && echo "ignored_test_names=$IGNORED_TEST_NAMES"
111-
} >> "$GITHUB_OUTPUT"
112-
fi
113-
114-
# Clean up
115-
rm -f test_results.txt
116-
11799
# Return the perl script's exit code
118100
exit $perl_exit_code

packaging/rpm/el/SPECS/apache-cloudberry-db-incubating.spec

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
%define cloudberry_install_dir /usr/local/cloudberry-db
22

3+
# Add at the top of the spec file
4+
# Default to non-debug build
5+
%bcond_with debug
6+
7+
# Conditional stripping based on debug flag
8+
%if %{with debug}
9+
%define __os_install_post %{nil}
10+
%define __strip /bin/true
11+
%define debug_package %{nil}
12+
%endif
13+
314
Name: apache-cloudberry-db-incubating
415
Version: %{version}
16+
# In the release definition section
17+
%if %{with debug}
18+
Release: %{release}.debug%{?dist}
19+
%else
520
Release: %{release}%{?dist}
21+
%endif
622
Summary: High-performance, open-source data warehouse based on PostgreSQL/Greenplum
723

824
License: ASL 2.0

0 commit comments

Comments
 (0)