Bug Summary

File:ddb/db_run.c
Warning:line 189, column 3
Value stored to 'ins' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd7.4 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name db_run.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model static -mframe-pointer=all -relaxed-aliasing -ffp-contract=on -fno-rounding-math -mconstructor-aliases -ffreestanding -mcmodel=kernel -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -target-feature -sse2 -target-feature -sse -target-feature -3dnow -target-feature -mmx -target-feature +save-args -target-feature +retpoline-external-thunk -disable-red-zone -no-implicit-float -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/sys/arch/amd64/compile/GENERIC.MP/obj -nostdsysteminc -nobuiltininc -resource-dir /usr/local/llvm16/lib/clang/16 -I /usr/src/sys -I /usr/src/sys/arch/amd64/compile/GENERIC.MP/obj -I /usr/src/sys/arch -I /usr/src/sys/dev/pci/drm/include -I /usr/src/sys/dev/pci/drm/include/uapi -I /usr/src/sys/dev/pci/drm/amd/include/asic_reg -I /usr/src/sys/dev/pci/drm/amd/include -I /usr/src/sys/dev/pci/drm/amd/amdgpu -I /usr/src/sys/dev/pci/drm/amd/display -I /usr/src/sys/dev/pci/drm/amd/display/include -I /usr/src/sys/dev/pci/drm/amd/display/dc -I /usr/src/sys/dev/pci/drm/amd/display/amdgpu_dm -I /usr/src/sys/dev/pci/drm/amd/pm/inc -I /usr/src/sys/dev/pci/drm/amd/pm/legacy-dpm -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu/inc -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu/smu11 -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu/smu12 -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu/smu13 -I /usr/src/sys/dev/pci/drm/amd/pm/powerplay/inc -I /usr/src/sys/dev/pci/drm/amd/pm/powerplay/hwmgr -I /usr/src/sys/dev/pci/drm/amd/pm/powerplay/smumgr -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu/inc -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu/inc/pmfw_if -I /usr/src/sys/dev/pci/drm/amd/display/dc/inc -I /usr/src/sys/dev/pci/drm/amd/display/dc/inc/hw -I /usr/src/sys/dev/pci/drm/amd/display/dc/clk_mgr -I /usr/src/sys/dev/pci/drm/amd/display/modules/inc -I /usr/src/sys/dev/pci/drm/amd/display/modules/hdcp -I /usr/src/sys/dev/pci/drm/amd/display/dmub/inc -I /usr/src/sys/dev/pci/drm/i915 -D DDB -D DIAGNOSTIC -D KTRACE -D ACCOUNTING -D KMEMSTATS -D PTRACE -D POOL_DEBUG -D CRYPTO -D SYSVMSG -D SYSVSEM -D SYSVSHM -D UVM_SWAP_ENCRYPT -D FFS -D FFS2 -D FFS_SOFTUPDATES -D UFS_DIRHASH -D QUOTA -D EXT2FS -D MFS -D NFSCLIENT -D NFSSERVER -D CD9660 -D UDF -D MSDOSFS -D FIFO -D FUSE -D SOCKET_SPLICE -D TCP_ECN -D TCP_SIGNATURE -D INET6 -D IPSEC -D PPP_BSDCOMP -D PPP_DEFLATE -D PIPEX -D MROUTING -D MPLS -D BOOT_CONFIG -D USER_PCICONF -D APERTURE -D MTRR -D NTFS -D SUSPEND -D HIBERNATE -D PCIVERBOSE -D USBVERBOSE -D WSDISPLAY_COMPAT_USL -D WSDISPLAY_COMPAT_RAWKBD -D WSDISPLAY_DEFAULTSCREENS=6 -D X86EMU -D ONEWIREVERBOSE -D MULTIPROCESSOR -D MAXUSERS=80 -D _KERNEL -O2 -Wno-pointer-sign -Wno-address-of-packed-member -Wno-constant-conversion -Wno-unused-but-set-variable -Wno-gnu-folding-constant -fdebug-compilation-dir=/usr/src/sys/arch/amd64/compile/GENERIC.MP/obj -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fcf-protection=branch -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -o /home/ben/Projects/scan/2024-01-11-110808-61670-1 -x c /usr/src/sys/ddb/db_run.c
1/* $OpenBSD: db_run.c,v 1.31 2023/03/08 04:43:07 guenther Exp $ */
2/* $NetBSD: db_run.c,v 1.8 1996/02/05 01:57:12 christos Exp $ */
3
4/*
5 * Mach Operating System
6 * Copyright (c) 1993,1992,1991,1990 Carnegie Mellon University
7 * All Rights Reserved.
8 *
9 * Permission to use, copy, modify and distribute this software and its
10 * documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation.
14 *
15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
17 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 *
19 * Carnegie Mellon requests users of this software to return to
20 *
21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
25 *
26 * any improvements or extensions that they make and grant Carnegie Mellon
27 * the rights to redistribute these changes.
28 *
29 * Author: David B. Golub, Carnegie Mellon University
30 * Date: 7/90
31 */
32
33/*
34 * Commands to run process.
35 */
36#include <sys/param.h>
37#include <sys/systm.h>
38
39#include <machine/db_machdep.h>
40
41#include <ddb/db_run.h>
42#include <ddb/db_break.h>
43#include <ddb/db_access.h>
44
45#ifdef SOFTWARE_SSTEP
46db_breakpoint_t db_not_taken_bkpt = 0;
47db_breakpoint_t db_taken_bkpt = 0;
48#endif
49
50int db_inst_count;
51
52#include <ddb/db_watch.h>
53#include <ddb/db_output.h>
54#include <ddb/db_sym.h>
55#include <ddb/db_extern.h>
56
57int db_run_mode;
58#define STEP_NONE0 0
59#define STEP_ONCE1 1
60#define STEP_RETURN2 2
61#define STEP_CALLT3 3
62#define STEP_CONTINUE4 4
63#define STEP_INVISIBLE5 5
64#define STEP_COUNT6 6
65
66int db_sstep_print;
67int db_loop_count;
68int db_call_depth;
69
70int
71db_stop_at_pc(db_regs_t *regs, int *is_breakpoint)
72{
73 vaddr_t pc, old_pc;
74 db_breakpoint_t bkpt;
75
76 db_clear_breakpoints();
77 db_clear_watchpoints();
78 old_pc = pc = PC_REGS(regs)((vaddr_t)(regs)->tf_rip);
79
80#ifdef FIXUP_PC_AFTER_BREAK
81 if (*is_breakpoint) {
82 /*
83 * Breakpoint trap. Fix up the PC if the
84 * machine requires it.
85 */
86 FIXUP_PC_AFTER_BREAK(regs)((regs)->tf_rip -= (1));
87 pc = PC_REGS(regs)((vaddr_t)(regs)->tf_rip);
88 }
89#endif
90
91 /*
92 * Now check for a breakpoint at this address.
93 */
94 bkpt = db_find_breakpoint(pc);
95 if (bkpt) {
96 if (--bkpt->count == 0) {
97 db_clear_single_step(regs)((regs)->tf_rflags &= ~0x00000100);
98 bkpt->count = bkpt->init_count;
99 *is_breakpoint = 1;
100 return 1; /* stop here */
101 }
102 } else if (*is_breakpoint
103#ifdef SOFTWARE_SSTEP
104 && !((db_taken_bkpt && db_taken_bkpt->address == pc) ||
105 (db_not_taken_bkpt && db_not_taken_bkpt->address == pc))
106#endif
107 ) {
108#ifdef PC_ADVANCE
109 PC_ADVANCE(regs);
110#else
111# ifdef SET_PC_REGS
112 SET_PC_REGS(regs, old_pc)(regs)->tf_rip = (int64_t)(old_pc);
113# else
114 PC_REGS(regs)((vaddr_t)(regs)->tf_rip) = old_pc;
115# endif
116#endif
117 }
118 db_clear_single_step(regs)((regs)->tf_rflags &= ~0x00000100);
119
120 *is_breakpoint = 0;
121
122 if (db_run_mode == STEP_INVISIBLE5) {
123 db_run_mode = STEP_CONTINUE4;
124 return 0; /* continue */
125 }
126 if (db_run_mode == STEP_COUNT6) {
127 return 0; /* continue */
128 }
129 if (db_run_mode == STEP_ONCE1) {
130 if (--db_loop_count > 0) {
131 if (db_sstep_print) {
132 db_printf("\t\t");
133 db_print_loc_and_inst(pc);
134 db_printf("\n");
135 }
136 return 0; /* continue */
137 }
138 }
139 if (db_run_mode == STEP_RETURN2) {
140 db_expr_t ins = db_get_value(pc, sizeof(int), 0);
141
142 /* continue until matching return */
143
144 if (!inst_trap_return(ins)(((ins)&0xff) == 0xcf) &&
145 (!inst_return(ins)(((ins)&0xff) == 0xc3) || --db_call_depth != 0)) {
146 if (db_sstep_print) {
147 if (inst_call(ins)(((ins)&0xff) == 0xe8 || (((ins)&0xff) == 0xff &&
((ins)&0x3800) == 0x1000))
|| inst_return(ins)(((ins)&0xff) == 0xc3)) {
148 int i;
149
150 db_printf("[after %6d] ", db_inst_count);
151 for (i = db_call_depth; --i > 0; )
152 db_printf(" ");
153 db_print_loc_and_inst(pc);
154 db_printf("\n");
155 }
156 }
157 if (inst_call(ins)(((ins)&0xff) == 0xe8 || (((ins)&0xff) == 0xff &&
((ins)&0x3800) == 0x1000))
)
158 db_call_depth++;
159 return 0; /* continue */
160 }
161 }
162 if (db_run_mode == STEP_CALLT3) {
163 db_expr_t ins = db_get_value(pc, sizeof(int), 0);
164
165 /* continue until call or return */
166
167 if (!inst_call(ins)(((ins)&0xff) == 0xe8 || (((ins)&0xff) == 0xff &&
((ins)&0x3800) == 0x1000))
&& !inst_return(ins)(((ins)&0xff) == 0xc3) &&
168 !inst_trap_return(ins)(((ins)&0xff) == 0xcf)) {
169 return 0; /* continue */
170 }
171 }
172 db_run_mode = STEP_NONE0;
173 return 1;
174}
175
176void
177db_restart_at_pc(db_regs_t *regs, int watchpt)
178{
179 vaddr_t pc = PC_REGS(regs)((vaddr_t)(regs)->tf_rip);
180
181 if ((db_run_mode == STEP_COUNT6) || (db_run_mode == STEP_RETURN2) ||
182 (db_run_mode == STEP_CALLT3)) {
183 db_expr_t ins;
184
185 /*
186 * We are about to execute this instruction,
187 * so count it now.
188 */
189 ins = db_get_value(pc, sizeof(int), 0);
Value stored to 'ins' is never read
190 db_inst_count++;
191#ifdef SOFTWARE_SSTEP
192 /* XXX works on mips, but... */
193 if (inst_branch(ins) || inst_call(ins)(((ins)&0xff) == 0xe8 || (((ins)&0xff) == 0xff &&
((ins)&0x3800) == 0x1000))
) {
194 ins = db_get_value(next_instr_address(pc, 1),
195 sizeof(int), 0);
196 db_inst_count++;
197 }
198#endif /* SOFTWARE_SSTEP */
199 }
200
201 if (db_run_mode == STEP_CONTINUE4) {
202 if (watchpt || db_find_breakpoint(pc)) {
203 /*
204 * Step over breakpoint/watchpoint.
205 */
206 db_run_mode = STEP_INVISIBLE5;
207 db_set_single_step(regs)((regs)->tf_rflags |= 0x00000100);
208 } else {
209 db_set_breakpoints();
210 db_set_watchpoints();
211 }
212 } else {
213 db_set_single_step(regs)((regs)->tf_rflags |= 0x00000100);
214 }
215}
216
217void
218db_single_step(db_regs_t *regs)
219{
220 if (db_run_mode == STEP_CONTINUE4) {
221 db_run_mode = STEP_INVISIBLE5;
222 db_set_single_step(regs)((regs)->tf_rflags |= 0x00000100);
223 }
224}
225
226/* single-step */
227void
228db_single_step_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
229{
230 int print = 0;
231
232 if (count == -1)
233 count = 1;
234
235 if (modif[0] == 'p')
236 print = 1;
237
238 db_run_mode = STEP_ONCE1;
239 db_loop_count = count;
240 db_sstep_print = print;
241 db_inst_count = 0;
242
243 db_cmd_loop_done = 1;
244}
245
246/* trace and print until call/return */
247void
248db_trace_until_call_cmd(db_expr_t addr, int have_addr, db_expr_t count,
249 char *modif)
250{
251 int print = 0;
252
253 if (modif[0] == 'p')
254 print = 1;
255
256 db_run_mode = STEP_CALLT3;
257 db_sstep_print = print;
258 db_inst_count = 0;
259
260 db_cmd_loop_done = 1;
261}
262
263void
264db_trace_until_matching_cmd(db_expr_t addr, int have_addr, db_expr_t count,
265 char *modif)
266{
267 int print = 0;
268
269 if (modif[0] == 'p')
270 print = 1;
271
272 db_run_mode = STEP_RETURN2;
273 db_call_depth = 1;
274 db_sstep_print = print;
275 db_inst_count = 0;
276
277 db_cmd_loop_done = 1;
278}
279
280/* continue */
281void
282db_continue_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
283{
284 if (modif[0] == 'c')
285 db_run_mode = STEP_COUNT6;
286 else
287 db_run_mode = STEP_CONTINUE4;
288 db_inst_count = 0;
289
290 db_cmd_loop_done = 1;
291}
292
293#ifdef SOFTWARE_SSTEP
294/*
295 * Software implementation of single-stepping.
296 * If your machine does not have a trace mode
297 * similar to the vax or sun ones you can use
298 * this implementation, done for the mips.
299 * Just define the above conditional and provide
300 * the functions/macros defined below.
301 *
302 * extern int
303 * inst_branch(ins), returns true if the instruction might branch
304 * extern unsigned
305 * branch_taken(ins, pc, getreg_val, regs),
306 * return the address the instruction might
307 * branch to
308 * getreg_val(regs, reg), return the value of a user register,
309 * as indicated in the hardware instruction
310 * encoding, e.g. 8 for r8
311 *
312 * next_instr_address(pc, bd) returns the address of the first
313 * instruction following the one at "pc",
314 * which is either in the taken path of
315 * the branch (bd==1) or not. This is
316 * for machines (mips) with branch delays.
317 *
318 * A single-step may involve at most 2 breakpoints -
319 * one for branch-not-taken and one for branch taken.
320 * If one of these addresses does not already have a breakpoint,
321 * we allocate a breakpoint and save it here.
322 * These breakpoints are deleted on return.
323 */
324
325void
326db_set_single_step(db_regs_t *regs)((db_regs_t *regs)->tf_rflags |= 0x00000100)
327{
328 vaddr_t pc = PC_REGS(regs)((vaddr_t)(regs)->tf_rip);
329#ifndef SOFTWARE_SSTEP_EMUL
330 vaddr_t brpc;
331 u_int inst;
332
333 /*
334 * User was stopped at pc, e.g. the instruction
335 * at pc was not executed.
336 */
337 inst = db_get_value(pc, sizeof(int), 0);
338 if (inst_branch(inst) || inst_call(inst)(((inst)&0xff) == 0xe8 || (((inst)&0xff) == 0xff &&
((inst)&0x3800) == 0x1000))
|| inst_return(inst)(((inst)&0xff) == 0xc3)) {
339 brpc = branch_taken(inst, pc, getreg_val, regs);
340 if (brpc != pc) { /* self-branches are hopeless */
341 db_taken_bkpt = db_set_temp_breakpoint(brpc);
342 }
343#if 0
344 /* XXX this seems like a true bug, no? */
345 pc = next_instr_address(pc, 1);
346#endif
347 }
348#endif /*SOFTWARE_SSTEP_EMUL*/
349 pc = next_instr_address(pc, 0);
350 db_not_taken_bkpt = db_set_temp_breakpoint(pc);
351}
352
353void
354db_clear_single_step(db_regs_t *regs)((db_regs_t *regs)->tf_rflags &= ~0x00000100)
355{
356 if (db_taken_bkpt != 0) {
357 db_delete_temp_breakpoint(db_taken_bkpt);
358 db_taken_bkpt = 0;
359 }
360 if (db_not_taken_bkpt != 0) {
361 db_delete_temp_breakpoint(db_not_taken_bkpt);
362 db_not_taken_bkpt = 0;
363 }
364}
365
366#endif /* SOFTWARE_SSTEP */