foundry icon indicating copy to clipboard operation
foundry copied to clipboard

bug(`forge script`): `--debug` doesn't show source code

Open AmesCornish opened this issue 2 years ago • 14 comments

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.

AmesCornish avatar Jul 19 '23 15:07 AmesCornish

Seeing this on my end as well.

emo-eth avatar Jul 28 '23 00:07 emo-eth

image image

Same here, with the latest version.

brucexu-eth avatar Aug 03 '23 22:08 brucexu-eth

Closing @Evalir ?

iFrostizz avatar Sep 13 '23 06:09 iFrostizz

Verified, working on my side. Thanks. image

brucexu-eth avatar Sep 17 '23 23:09 brucexu-eth

image the docs says it should show source code https://book.getfoundry.sh/forge/debugger

block0xhash avatar Oct 11 '23 14:10 block0xhash

I got same issues on my side. image

knownothing10 avatar Dec 07 '23 09:12 knownothing10

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.

emo-eth avatar Dec 17 '23 19:12 emo-eth

Hard to say without having a reproducible example @emo-eth

iFrostizz avatar Dec 17 '23 23:12 iFrostizz

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?

0xGuybrush avatar Jan 15 '24 10:01 0xGuybrush

#7058 will hopefully resolve some of these issues

emo-eth avatar Feb 09 '24 03:02 emo-eth

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?

zerosnacks avatar Jul 03 '24 11:07 zerosnacks

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:

Screenshot 2024-07-03 at 15 36 00

2. Sometimes gives "No source map for contract DebugRemote":

Screenshot 2024-07-03 at 15 36 06

I think that's just for certain opcodes though, then keeps going and shows source again on the DebugRemote contract:

Screenshot 2024-07-03 at 15 36 16

3. Gives error when it drops into deployed Counter contract:

Screenshot 2024-07-03 at 15 36 47

4. Shows source again when it returns to DebugRemote:

Screenshot 2024-07-03 at 15 37 07

Hope this helps, let me know if I can give more details

0xGuybrush avatar Jul 03 '24 14:07 0xGuybrush

Hope this helps, let me know if I can give more details

Awesome! This helps a ton

zerosnacks avatar Jul 03 '24 14:07 zerosnacks