forked from eclipse-cdt-cloud/cdt-gdb-adapter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for setting the cwd of the gdb process
For some use cases the executable being debugged expects to find its sources relative to the current working directory ($cwd) instead of the compilation directory ($cdir). This can happen in a couple of circumstances: 1. The source and executable have been moved from the location it was compiled from. 2. The compiler did not save the compilation directory for the given file. The compilation directory can be examined with "info source" in the GDB debugger console.
- Loading branch information
1 parent
3779028
commit 4da450b
Showing
7 changed files
with
210 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/********************************************************************* | ||
* Copyright (c) 2023 Kichwa Coders Canada Inc. and others | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*********************************************************************/ | ||
|
||
import * as path from 'path'; | ||
import { CdtDebugClient } from './debugClient'; | ||
import { | ||
fillDefaults, | ||
resolveLineTagLocations, | ||
standardBeforeEach, | ||
testProgramsDir, | ||
} from './utils'; | ||
import { expect } from 'chai'; | ||
|
||
/** | ||
* To test that cwd is set properly we remove the compilation directory from the executable, | ||
* see the makefile for that part, and then launch with a variety of executable/cwd locations | ||
* to make sure that we can insert breakpoints when we expect to, and cannot insert breakpoints | ||
* when we force gdb not to be able to find the source | ||
*/ | ||
describe.only('gdb cwd', function () { | ||
let dc: CdtDebugClient; | ||
const program = path.join(testProgramsDir, 'cwd.exe'); | ||
const programRelocated = path.join(testProgramsDir, 'Debug', 'cwd.exe'); | ||
const src = path.join(testProgramsDir, 'cwd.c'); | ||
const lineTags = { | ||
'STOP HERE': 0, | ||
}; | ||
|
||
before(function () { | ||
resolveLineTagLocations(src, lineTags); | ||
}); | ||
|
||
beforeEach(async function () { | ||
dc = await standardBeforeEach(); | ||
}); | ||
|
||
afterEach(async function () { | ||
await dc.stop(); | ||
}); | ||
|
||
it('default cwd finds source in program directory', async function () { | ||
await dc.launchRequest( | ||
fillDefaults(this.test, { | ||
program: program, | ||
}) | ||
); | ||
|
||
const bps = await dc.setBreakpointsRequest({ | ||
lines: [lineTags['STOP HERE']], | ||
breakpoints: [{ line: lineTags['STOP HERE'], column: 1 }], | ||
source: { path: src }, | ||
}); | ||
expect(bps.body.breakpoints[0].verified).to.eq(true); | ||
}); | ||
|
||
it('explicit cwd finds source in program directory', async function () { | ||
await dc.launchRequest( | ||
fillDefaults(this.test, { | ||
program: program, | ||
cwd: testProgramsDir, | ||
}) | ||
); | ||
|
||
const bps = await dc.setBreakpointsRequest({ | ||
lines: [lineTags['STOP HERE']], | ||
breakpoints: [{ line: lineTags['STOP HERE'], column: 1 }], | ||
source: { path: src }, | ||
}); | ||
expect(bps.body.breakpoints[0].verified).to.eq(true); | ||
}); | ||
|
||
it('default cwd does not find source with relocated program', async function () { | ||
await dc.launchRequest( | ||
fillDefaults(this.test, { | ||
program: programRelocated, | ||
}) | ||
); | ||
|
||
const bps = await dc.setBreakpointsRequest({ | ||
lines: [lineTags['STOP HERE']], | ||
breakpoints: [{ line: lineTags['STOP HERE'], column: 1 }], | ||
source: { path: src }, | ||
}); | ||
expect(bps.body.breakpoints[0].verified).to.eq(false); | ||
}); | ||
|
||
it('explicitly incorrect cwd does not finds source with relocated program', async function () { | ||
await dc.launchRequest( | ||
fillDefaults(this.test, { | ||
program: programRelocated, | ||
cwd: path.join(testProgramsDir, 'EmptyDir'), | ||
}) | ||
); | ||
|
||
const bps = await dc.setBreakpointsRequest({ | ||
lines: [lineTags['STOP HERE']], | ||
breakpoints: [{ line: lineTags['STOP HERE'], column: 1 }], | ||
source: { path: src }, | ||
}); | ||
expect(bps.body.breakpoints[0].verified).to.eq(false); | ||
}); | ||
|
||
it('explicitly correct cwd does find source with relocated program', async function () { | ||
await dc.launchRequest( | ||
fillDefaults(this.test, { | ||
program: programRelocated, | ||
cwd: testProgramsDir, | ||
}) | ||
); | ||
|
||
const bps = await dc.setBreakpointsRequest({ | ||
lines: [lineTags['STOP HERE']], | ||
breakpoints: [{ line: lineTags['STOP HERE'], column: 1 }], | ||
source: { path: src }, | ||
}); | ||
expect(bps.body.breakpoints[0].verified).to.eq(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
int main(int argc, char *argv[]) | ||
{ | ||
return 0; // STOP HERE | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters