leuat / TRSE

Turbo Rascal Syntax Error full repo
GNU General Public License v3.0
242 stars 44 forks source link

Segmentation fault when pressing Ctrl-R on asm file for Amstrad CPC #569

Closed ColinPitrat closed 3 years ago

ColinPitrat commented 3 years ago

When in my project, if I double click on a .asm file and then press Ctrl-R to run it segfaults. It works fine on the .ras file and I get a clear error message on a .tru file.

This occurs because m_assembler is null when reaching SetupMemoryAnalyzer (line 120). I'm not yet sure how to properly fix this though because just returning false here makes TRSE think the running doesn't finish.

(gdb) bt                                                                                                                                                                                                                                                                                  
#0  0x000056037deb3f34 in QVector<QSharedPointer<MemoryBlock> >::isDetached() const (this=0x1c8) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qvector.h:113                                                                                                                                
#1  0x000056037e00a32e in QVector<QSharedPointer<MemoryBlock> >::detach() (this=0x1c8) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qvector.h:404                                                                                                                                          
#2  0x000056037e009450 in QVector<QSharedPointer<MemoryBlock> >::begin() (this=0x1c8) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qvector.h:210                                                                                                                                           
#3  0x000056037e0110fb in CompilerZ80::SetupMemoryAnalyzer(QString, Orgasm*) (this=0x7faa58096e40, filename=..., orgAsm=0x0) at source/Compiler/compilers/compilerz80.cpp:120                                                                                                             
#4  0x000056037e15fcaa in BuilderThread::run() (this=0x56038244d188) at source/trsedocuments/formraseditor.cpp:1317                          
#5  0x00007faa96137b81 in  () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5                                                                   
#6  0x00007faa95fc8ea7 in start_thread (arg=<optimized out>) at pthread_create.c:477                                                         
#7  0x00007faa95b8ddef in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95                                                                                                                                                                                                        
(gdb) p d                                                                                                                                                                                                                                                                                 
Cannot access memory at address 0x1c8                                                                                                        
(gdb) p this                                                                                                                                                                                                                                                                              
$1 = (const QVector<QSharedPointer<MemoryBlock> > * const) 0x1c8                                                                             
(gdb) frame 3                                                                                                                                
#3  0x000056037e0110fb in CompilerZ80::SetupMemoryAnalyzer (this=0x7faa58096e40, filename=..., orgAsm=0x0) at source/Compiler/compilers/compilerz80.cpp:120
120         for (QSharedPointer<MemoryBlock> mb: m_assembler->blocks) {                                                                      
(gdb) list                                                                                                                                   
115         QString assembler = m_ini->getString("pasmo");                                                                                   
116         QString output;                                                                                                                  
117         Syntax::s.m_currentSystem->StartProcess(assembler, QStringList() << "-1"<< filename+".asm" <<filename+".bin", output, true);     
118                                                                                                                                          
119         QVector<QSharedPointer<MemoryBlock>> nb;                                                                                         
120         for (QSharedPointer<MemoryBlock> mb: m_assembler->blocks) {                                                                      
121             if (mb->m_type == MemoryBlock::USER)                                                                                                                                                                                                                                      
122                 nb.append(mb);                                                                                                           
123         }                                                                                                                                                                                                                                                                             
124          
ColinPitrat commented 3 years ago

One option could be to add another check in ./source/trsedocuments/formraseditor.cpp to discard .asm files as well as .tru, but it seems like this would need to be extended to any format file I could open ...

leuat commented 3 years ago

ah yes I haven't set up compiling .asm files directly on the z80 / x86 / m68k - only the 6502 .asm files can currently execute and run. I'll make sure that Ctrl+R won't work on .asm files on the Z80/ x86/m68k until this gets requested.. gotta prioritize! thanks for reporting this =)

leuat commented 3 years ago

Quick fix: at least it doesn't crash when trying to compile an assembly file, but still no support for being able to compile and run .asm files directly. If you are interested in having this as a feature, then please create a new request issue! Thansk for reporting this =)

ColinPitrat commented 3 years ago

Nope, I don't really need this for now, it's just that it was crashing when I was pressing Ctrl-R without thinking where I was.

Thanks!