foundry
foundry copied to clipboard
bug(`forge script`): `--debug` doesn't show source code
Component
Forge
Have you ensured that all of these are up to date?
- [ ] Foundry
- [X] Foundryup
What version of Foundry are you on?
nightly 0e72b71
What command(s) is the bug in?
forge script --debug
Operating System
Linux
Describe the bug
Source code debugging seems to have recently broken. In the current nightly (0e72b71), I can do the following:
foundryup --commit 0e72b71 forge init forge script --debug script/Counter.s.sol
..and where the source should be, it says "Unknown contract at address 0x5b73...0519"
Earlier versions, for example 288ab2e from about 2 week ago, correctly show and step through the source.
Also, I have not been able to get any recent versions to show source code when stepping into on-chain contracts, even though I've set my ETHERSCAN_API_KEY in env and toml.
Seeing this on my end as well.
Same here, with the latest version.
Closing @Evalir ?
Verified, working on my side. Thanks.
the docs says it should show source code https://book.getfoundry.sh/forge/debugger
I got same issues on my side.
cc @iFrostizz @Evalir, this seemed to be mitigated at the time, but I am frequently (inconsistently) not able to view sourcemap for te actual contract(s) I am testing – the test contract sourcemap works fine, but calls to the actual logic contract show no sourcemap. Looks like other users are running into this as well.
Hard to say without having a reproducible example @emo-eth
I can look to work up a MCVE for this, if useful because we're hitting the same.
I just want to make sure I understand how it's meant to work correctly to rule out any false assumption on my part. So at the moment I'm trying to debug a deployed contract via forking like this:
CONTRACT=<contract-address> forge debug --debug scripts/DebugRemote.s.sol --fork-url $RPC_URL
DebugRemote.s.sol then looks like this:
pragma solidity ^0.8.22;
import {Script} from "forge-std/Script.sol";
import {console2} from "forge-std/console2.sol";
import {MyContract} from "../src/MyContract.sol";
contract DebugRemote is Script {
address private CONTRACT = vm.envOr("CONTRACT", address(0));
function run() public {
require(CONTRACT != address(0), "CONTRACT env var missing");
MyContract(INFO_CONTRACT).fooBar();
}
}
When I'm walking through the debugger it shows me the source code for the DebugRemote script itself no problem, but as soon as it steps into fooBar() it says:
Unknown contract at address
<contract-address>
MyContract.sol exists in my local repo (though it's not validated on-chain). I've ran a full forge clean && forge build before running the script, and the repo code matches the deployed.
Should forge debug be able to link the source code in this scenario and display it or have I misunderstood?
#7058 will hopefully resolve some of these issues
Hi @0xGuybrush, sorry for the delay. Would be great to have a minimal reproduction of this!
@emo-eth are you still experiencing issues with this since https://github.com/foundry-rs/foundry/issues/7111 + https://github.com/foundry-rs/foundry/pull/7058?
Hi @0xGuybrush, sorry for the delay. Would be great to have a minimal reproduction of this!
Hi @zerosnacks. Yes absolutely! Please check it out here. I've just added a script to the default foundry init project, and then written up steps to reproduce in the README.
Happening still with foundryup as of this morning.
I'm seeing a flow like this:
1. Behaving as expected in the DebugRemote contract itself:
2. Sometimes gives "No source map for contract DebugRemote":
I think that's just for certain opcodes though, then keeps going and shows source again on the DebugRemote contract:
3. Gives error when it drops into deployed Counter contract:
4. Shows source again when it returns to DebugRemote:
Hope this helps, let me know if I can give more details
Hope this helps, let me know if I can give more details
Awesome! This helps a ton