Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] --debug-level full crashes when importing #3917

Open
josiahls opened this issue Dec 28, 2024 · 1 comment
Open

[BUG] --debug-level full crashes when importing #3917

josiahls opened this issue Dec 28, 2024 · 1 comment
Labels
bug Something isn't working crash debug-info mojo-repo Tag all issues with this label

Comments

@josiahls
Copy link

josiahls commented Dec 28, 2024

Bug description

Running a mojo script using the debugger seg faults, as opposed to when running regular mojo, which runs to completion (although I have noticed strange behavior in the regular script).

I've isolated this to specifically debug symbols from --debug-level full

Also even more specifically, this fails when importing the example module below. This works fine if running inside the same module file.

Steps to reproduce

  • Include relevant code snippet or link to code that did not work as expected.

c_binder_mojo/c_binder_mojo/minimal_example.mojo

from collections import Optional,Dict,Set
from memory import UnsafePointer
from utils import Variant
from pathlib import Path
import os

struct AstNode(CollectionElement):
    var parent:   UnsafePointer[AstNode]

    fn __init__(mut self):
        self.parent   = UnsafePointer[Self]()

    fn __moveinit__(mut self, owned existing:Self):
        self.parent = existing.parent

    fn __copyinit__(mut self, read existing:Self):
        self.parent = existing.parent


fn make_graph(path:Path) raises -> UnsafePointer[AstNode]:
    return UnsafePointer[AstNode]() 

c_binder_mojo/tests/test_ast_node.mojo

import os 
from pathlib import Path
from memory import UnsafePointer
from c_binder_mojo.minimal_example import make_graph


fn test_ast_node() raises:
    num_mojo_path = Path('fdsfdas') # Works when debug-level is not full
    root_node = make_graph(num_mojo_path)
    print('done')


fn main():
    try:
        test_ast_node()
        print('succeeded')
    except e:
        print('failed')

Remove the --debug-level full and this will suceed. This is preventing me from going into the debugger to debug more complex issues.

/home/fastrl_mojo_user/.vscode-server/data/User/globalStorage/modular-mojotools.vscode-mojo-nightly/magic-data-home/envs/max/bin/mojo run --debug-level full -I c_binder_mojo /home/fastrl_mojo_user/fastrl_mojo/c_binder_mojo/tests/test_debugg_failure.mojo

*edit. Looks like specifically having:

struct AstNode:
    var parent:   UnsafePointer[Self]

Segfaults when static typed to a unsafe pointer, when importing from a separate file

System information

- What OS did you do install Mojo on ?
ubuntu:22.04 docker image
- Provide version information for Mojo by pasting the output of `mojo -v`
/home/fastrl_mojo_user/.vscode-server/data/User/globalStorage/modular-mojotools.vscode-mojo-nightly/magic-data-home/envs/max/bin/mojo -v
mojo 25.1.0.dev2024122805 (3497ff0b)
- Provide Magic CLI version by pasting the output of `magic -V` or `magic --version` 
magic --version
magic 0.5.1 - (based on pixi 0.37.0)
- Optionally, provide more information with `magic info`.

 magic info
     Magic version: 0.5.1
System
------------
      Pixi version: 0.37.0
          Platform: linux-64
  Virtual packages: __unix=0=0
                  : __linux=5.4.0=0
                  : __glibc=2.35=0
                  : __archspec=1=skylake
         Cache dir: /home/fastrl_mojo_user/.cache/rattler/cache
      Auth storage: /home/fastrl_mojo_user/.rattler/credentials.json
  Config locations: No config files found

Global
------------
           Bin dir: /home/fastrl_mojo_user/.modular/bin
   Environment dir: /home/fastrl_mojo_user/.modular/envs
      Manifest dir: /home/fastrl_mojo_user/.modular/manifests/pixi-global.toml

Stacktrace

Fails on debug symbols

_binder_mojo /home/fastrl_mojo_user/fastrl_mojo/c_binder_mojo/tests/test_debugg_failure.mojo
Failed to initialize Crashpad. Crash reporting will not be available. Cause: while locating crashpad handler: unable to locate crashpad handler executable
Please submit a bug report to https://github.com/modularml/mojo/issues and include the crash backtrace along with all the relevant source codes.
Stack dump:
0. Program arguments: /home/fastrl_mojo_user/.vscode-server/data/User/globalStorage/modular-mojotools.vscode-mojo-nightly/magic-data-home/envs/max/bin/mojo run --debug-level full -I c_binder_mojo /home/fastrl_mojo_user/fastrl_mojo/c_binder_mojo/tests/test_debugg_failure.mojo
#0 0x000055627fc89e4b llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) Signals.cpp:0:0
#1 0x000055627fc87da9 llvm::sys::RunSignalHandlers() Signals.cpp:0:0
#2 0x000055627fc8a4cd SignalHandler(int) Signals.cpp:0:0
#3 0x00007fd273088520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x000055627d33f7ca M::DebugInfo::DIMemberType::print(mlir::AsmPrinter&) const DebugInfoTypes.cpp:0:0
#5 0x000055627d3487fd ZN4llvm10interleaveIPKN1M9DebugInfo12DIMemberTypeEZN4mlir10AsmPrinter23printStrippedAttrOrTypeIS3_TnPNSt9enable_ifIXsr23detect_has_print_methodIT_EE5valueEvE4typeELPv0EEEvNS_8ArrayRefISA_EEEUlS3_E_ZNS_10interleaveINSF_IS3_EESH_NS_11raw_ostreamES4_EEvRKSA_RT1_T0_RKNS_9StringRefEEUlvE_vEEvSA_SA_SP_SN DebugInfoTypes.cpp:0:0
#6 0x000055627d340b34 M::DebugInfo::DIStructType::print(mlir::AsmPrinter&) const DebugInfoTypes.cpp:0:0
#7 0x000055627d344abc M::DebugInfo::DebugInfoDialect::printType(mlir::Type, mlir::DialectAsmPrinter&) const DebugInfoTypes.cpp:0:0
#8 0x000055627fb74de3 mlir::AsmPrinter::Impl::printDialectType(mlir::Type) AsmPrinter.cpp:0:0
#9 0x000055627d341879 M::DebugInfo::DITargetIndependentPointerType::print(mlir::AsmPrinter&) const DebugInfoTypes.cpp:0:0
#10 0x000055627d344b73 M::DebugInfo::DebugInfoDialect::printType(mlir::Type, mlir::DialectAsmPrinter&) const DebugInfoTypes.cpp:0:0
#11 0x000055627fb74de3 mlir::AsmPrinter::Impl::printDialectType(mlir::Type) AsmPrinter.cpp:0:0
#12 0x000055627d341879 M::DebugInfo::DITargetIndependentPointerType::print(mlir::AsmPrinter&) const DebugInfoTypes.cpp:0:0
#13 0x000055627d344b73 M::DebugInfo::DebugInfoDialect::printType(mlir::Type, mlir::DialectAsmPrinter&) const DebugInfoTypes.cpp:0:0
#14 0x000055627fb74de3 mlir::AsmPrinter::Impl::printDialectType(mlir::Type) AsmPrinter.cpp:0:0
#15 0x000055627fb76ab7 mlir::Type::print(llvm::raw_ostream&, mlir::AsmState&) const AsmPrinter.cpp:0:0
#16 0x000055627d877589 mlir::bytecode::detail::IRNumberingState::number(mlir::Type) IRNumbering.cpp:0:0
#17 0x000055627d337d6d (anonymous namespace)::DebugInfoDialectBytecodeInterface::writeType(mlir::Type, mlir::DialectBytecodeWriter&) const DebugInfoDialect.cpp:0:0
#18 0x000055627d87750d mlir::bytecode::detail::IRNumberingState::number(mlir::Type) IRNumbering.cpp:0:0
#19 0x000055627d337938 (anonymous namespace)::DebugInfoDialectBytecodeInterface::writeAttribute(mlir::Attribute, mlir::DialectBytecodeWriter&) const DebugInfoDialect.cpp:0:0
#20 0x000055627d8767cd mlir::bytecode::detail::IRNumberingState::number(mlir::Attribute) IRNumbering.cpp:0:0
#21 0x000055627d3377da (anonymous namespace)::DebugInfoDialectBytecodeInterface::writeAttribute(mlir::Attribute, mlir::DialectBytecodeWriter&) const DebugInfoDialect.cpp:0:0
#22 0x000055627d8767cd mlir::bytecode::detail::IRNumberingState::number(mlir::Attribute) IRNumbering.cpp:0:0
#23 0x000055627fbc3eda (anonymous namespace)::BuiltinDialectBytecodeInterface::writeAttribute(mlir::Attribute, mlir::DialectBytecodeWriter&) const BuiltinDialectBytecode.cpp:0:0
#24 0x000055627d8767cd mlir::bytecode::detail::IRNumberingState::number(mlir::Attribute) IRNumbering.cpp:0:0
#25 0x000055627d876287 mlir::bytecode::detail::IRNumberingState::number(mlir::Operation&) IRNumbering.cpp:0:0
#26 0x000055627d876f73 mlir::bytecode::detail::IRNumberingState::number(mlir::Block&) IRNumbering.cpp:0:0
#27 0x000055627d8763b4 mlir::bytecode::detail::IRNumberingState::number(mlir::Region&) IRNumbering.cpp:0:0
#28 0x000055627d875761 mlir::bytecode::detail::IRNumberingState::IRNumberingState(mlir::Operation*, mlir::BytecodeWriterConfig const&) IRNumbering.cpp:0:0
#29 0x000055627d86a312 mlir::writeBytecodeToFile(mlir::Operation*, llvm::raw_ostream&, mlir::BytecodeWriterConfig const&) BytecodeWriter.cpp:0:0
#30 0x000055627d30a109 void llvm::detail::UniqueFunctionBase<void, M::AsyncRT::AsyncValueRef<std::vector<mlir::Diagnostic, std::allocatormlir::Diagnostic > >&&>::CallImpl<M::Cache::cachedTransform(mlir::Operation*, M::RCRef<M::Cache::BlobCache<M::Cache::TransformCacheKey> >, M::AsyncRT::AnyAsyncValueRef, mlir::PassManager&, std::function<void (mlir::Operation*)> const&, std::function<void (mlir::Operation*)> const&)::$_0::operator()(mlir::Operation*, M::RCRef<M::WriteableBuffer>, M::AsyncRT::AnyAsyncValueRef) const::'lambda'(M::AsyncRT::AsyncValueRef<std::vector<mlir::Diagnostic, std::allocatormlir::Diagnostic > >&&)>(void*, M::AsyncRT::AsyncValueRef<std::vector<mlir::Diagnostic, std::allocatormlir::Diagnostic > >&) CachedTransform.cpp:0:0
#31 0x000055627d309c67 void M::AsyncRT::AsyncValueRef<std::vector<mlir::Diagnostic, std::allocatormlir::Diagnostic > >::andThen(llvm::unique_function<void (M::AsyncRT::AsyncValueRef<std::vector<mlir::Diagnostic, std::allocatormlir::Diagnostic > >&&)>&&) && CachedTransform.cpp:0:0
#32 0x000055627d309430 M::AsyncRT::AnyAsyncValueRef llvm::detail::UniqueFunctionBase<M::AsyncRT::AnyAsyncValueRef, M::RCRef<M::WriteableBuffer>, M::AsyncRT::AnyAsyncValueRef>::CallImpl<M::AsyncRT::AnyAsyncValueRef M::Cache::cachedTransform<M::Cache::cachedTransform(mlir::Operation*, M::RCRef<M::Cache::BlobCache<M::Cache::TransformCacheKey> >, M::AsyncRT::AnyAsyncValueRef, mlir::PassManager&, std::function<void (mlir::Operation*)> const&, std::function<void (mlir::Operation*)> const&)::$_0, M::Cache::cachedTransform(mlir::Operation*, M::RCRef<M::Cache::BlobCache<M::Cache::TransformCacheKey> >, M::AsyncRT::AnyAsyncValueRef, mlir::PassManager&, std::function<void (mlir::Operation*)> const&, std::function<void (mlir::Operation*)> const&)::$_1>(mlir::Operation*, M::RCRef<M::Cache::BlobCache<M::Cache::TransformCacheKey> >, M::AsyncRT::AnyAsyncValueRef, M::RCRef<M::WriteableBuffer>, M::Cache::cachedTransform(mlir::Operation*, M::RCRef<M::Cache::BlobCache<M::Cache::TransformCacheKey> >, M::AsyncRT::AnyAsyncValueRef, mlir::PassManager&, std::function<void (mlir::Operation*)> const&, std::function<void (mlir::Operation*)> const&)::$_0&&, M::Cache::cachedTransform(mlir::Operation*, M::RCRef<M::Cache::BlobCache<M::Cache::TransformCacheKey> >, M::AsyncRT::AnyAsyncValueRef, mlir::PassManager&, std::function<void (mlir::Operation*)> const&, std::function<void (mlir::Operation*)> const&)::$_1&&)::'lambda'(M::RCRef<M::WriteableBuffer>, M::AsyncRT::AnyAsyncValueRef)>(void*, M::RCRef<M::WriteableBuffer>&, M::AsyncRT::AnyAsyncValueRef&) CachedTransform.cpp:0:0
#33 0x000055627d308e2b void llvm::detail::UniqueFunctionBase<void, M::AsyncRT::AsyncValueRef<std::optional<M::RCRef<M::Buffer> > >&&>::CallImpl<M::AsyncRT::AnyAsyncValueRef M::Cache::cachedTransform<M::AsyncRT::AnyAsyncValueRef M::Cache::cachedTransform<M::Cache::cachedTransform(mlir::Operation*, M::RCRef<M::Cache::BlobCache<M::Cache::TransformCacheKey> >, M::AsyncRT::AnyAsyncValueRef, mlir::PassManager&, std::function<void (mlir::Operation*)> const&, std::function<void (mlir::Operation*)> const&)::$_0, M::Cache::cachedTransform(mlir::Operation*, M::RCRef<M::Cache::BlobCache<M::Cache::TransformCacheKey> >, M::AsyncRT::AnyAsyncValueRef, mlir::PassManager&, std::function<void (mlir::Operation*)> const&, std::function<void (mlir::Operation*)> const&)::$_1>(mlir::Operation*, M::RCRef<M::Cache::BlobCache<M::Cache::TransformCacheKey> >, M::AsyncRT::AnyAsyncValueRef, M::RCRef<M::WriteableBuffer>, M::Cache::cachedTransform(mlir::Operation*, M::RCRef<M::Cache::BlobCache<M::Cache::TransformCacheKey> >, M::AsyncRT::AnyAsyncValueRef, mlir::PassManager&, std::function<void (mlir::Operation*)> const&, std::function<void (mlir::Operation*)> const&)::$_0&&, M::Cache::cachedTransform(mlir::Operation*, M::RCRef<M::Cache::BlobCache<M::Cache::TransformCacheKey> >, M::AsyncRT::AnyAsyncValueRef, mlir::PassManager&, std::function<void (mlir::Operation*)> const&, std::function<void (mlir::Operation*)> const&)::$_1&&)::'lambda'(M::RCRef<M::WriteableBuffer>, M::AsyncRT::AnyAsyncValueRef)>(M::AsyncRT::EncodedLocation, M::RCRef<M::Cache::BlobCache<M::Cache::TransformCacheKey> > const&, M::AsyncRT::AnyAsyncValueRef, M::RCRef<M::WriteableBuffer>, M::Cache::cachedTransform(mlir::Operation*, M::RCRef<M::Cache::BlobCache<M::Cache::TransformCacheKey> >, M::AsyncRT::AnyAsyncValueRef, mlir::PassManager&, std::function<void (mlir::Operation*)> const&, std::function<void (mlir::Operation*)> const&)::$_0, llvm::unique_function<M::AsyncRT::AnyAsyncValueRef (M::RCRef<M::Buffer>)>, bool)::'lambda'(M::AsyncRT::AsyncValueRef<std::optional<M::RCRef<M::Buffer> > >&&)>(void*, M::AsyncRT::AsyncValueRef<std::optional<M::RCRef<M::Buffer> > >&) CachedTransform.cpp:0:0
#34 0x000055627d31297d void (anonymous namespace)::WorkQueueThread::runItemsImpl<(anonymous namespace)::ThreadPoolWorkQueue::await(llvm::ArrayRef<M::AsyncRT::AnyAsyncValueRef>)::$_2, (anonymous namespace)::ThreadPoolWorkQueue::await(llvm::ArrayRef<M::AsyncRT::AnyAsyncValueRef>)::$_3>((anonymous namespace)::ThreadPoolWorkQueue::await(llvm::ArrayRef<M::AsyncRT::AnyAsyncValueRef>)::$_2, (anonymous namespace)::ThreadPoolWorkQueue::await(llvm::ArrayRef<M::AsyncRT::AnyAsyncValueRef>)::$_3, bool, llvm::StringLiteral, llvm::StringLiteral) ThreadPoolWorkQueue.cpp:0:0
#35 0x000055627f8a8659 M::Detail::runWithThreadAffinityLinux(unsigned long, llvm::function_ref<void ()>&) ThreadAffinity.cpp:0:0
#36 0x000055627f8a89fd M::runWithThreadAffinity(unsigned long, llvm::function_ref<void ()>) ThreadAffinity.cpp:0:0
#37 0x000055627d313b0c M::AsyncRT::runWithThreadAffinity(unsigned long, llvm::function_ref<void ()>) ThreadAffinity.cpp:0:0
#38 0x000055627d3115bc (anonymous namespace)::ThreadPoolWorkQueue::await(llvm::ArrayRef<M::AsyncRT::AnyAsyncValueRef>) ThreadPoolWorkQueue.cpp:0:0
#39 0x000055627ceb72bf M::KGEN::KGENCompiler::runKGENPipeline(mlir::ModuleOp, M::TargetInfoAttr, M::RCRef<M::Cache::BlobCache<M::Cache::TransformCacheKey> >, M::AsyncRT::AnyAsyncValueRef, std::function<void (mlir::Operation*)>, std::function<void (mlir::Operation*)>) KGENCompiler.cpp:0:0
#40 0x000055627ceb6ada M::KGEN::KGENCompiler::runKGENPipeline(mlir::ModuleOp, M::TargetInfoAttr) KGENCompiler.cpp:0:0
#41 0x000055627cd2ad0a run(M::State const&) mojo-run.cpp:0:0
#42 0x000055627cd34f2c main mojo.cpp:0:0
#43 0x00007fd27306fd90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#44 0x00007fd27306fe40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#45 0x000055627cd09525 _start (/home/fastrl_mojo_user/.vscode-server/data/User/globalStorage/modular-mojotools.vscode-mojo-nightly/magic-data-home/envs/max/bin/mojo+0x25d1525)
mojo crashed!
Please file a bug report.
Segmentation fault (core dumped)

@josiahls josiahls added bug Something isn't working mojo-repo Tag all issues with this label labels Dec 28, 2024
@josiahls josiahls changed the title [BUG] --debug-level full crashes script [BUG] --debug-level full crashes when importing Dec 28, 2024
@josiahls
Copy link
Author

josiahls commented Jan 3, 2025

Another weird wrinkle here:

@value
struct AstNode:
    var parent: List[ArcPointer[Self]]

fn make_graph(path:Path) raises -> ArcPointer[AstNode]:...

In another module:

node = AstNode(...) # seg faults

But

node = make_graph(...) # works fine

This is still related to self referencial stuff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working crash debug-info mojo-repo Tag all issues with this label
Projects
None yet
Development

No branches or pull requests

2 participants