mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 20:42:43 +00:00 
			
		
		
		
	AK: Make MappedFile heap-allocated and ref-counted
Let's adapt this class a bit better to how it's actually being used. Instead of having valid/invalid states and storing an error in case it's invalid, a MappedFile is now always valid, and the factory function that creates it will return an OSError if mapping fails.
This commit is contained in:
		
							parent
							
								
									70fce5c4c7
								
							
						
					
					
						commit
						2f3b901f7f
					
				
					 36 changed files with 184 additions and 199 deletions
				
			
		|  | @ -42,13 +42,6 @@ DebugSession::DebugSession(pid_t pid, String source_root) | |||
| { | ||||
| } | ||||
| 
 | ||||
| MappedFile DebugSession::map_executable_for_process(pid_t pid) | ||||
| { | ||||
|     MappedFile executable(String::formatted("/proc/{}/exe", pid)); | ||||
|     ASSERT(executable.is_valid()); | ||||
|     return executable; | ||||
| } | ||||
| 
 | ||||
| DebugSession::~DebugSession() | ||||
| { | ||||
|     if (m_is_debuggee_dead) | ||||
|  | @ -373,13 +366,13 @@ void DebugSession::update_loaded_libs() | |||
|         if (m_loaded_libraries.contains(lib_name)) | ||||
|             return IterationDecision::Continue; | ||||
| 
 | ||||
|         MappedFile lib_file(object_path.value()); | ||||
|         if (!lib_file.is_valid()) | ||||
|         auto file_or_error = MappedFile ::map(object_path.value()); | ||||
|         if (file_or_error.is_error()) | ||||
|             return IterationDecision::Continue; | ||||
| 
 | ||||
|         FlatPtr base_address = entry.as_object().get("address").as_u32(); | ||||
|         auto debug_info = make<DebugInfo>(make<ELF::Image>(reinterpret_cast<const u8*>(lib_file.data()), lib_file.size()), m_source_root, base_address); | ||||
|         auto lib = make<LoadedLibrary>(lib_name, move(lib_file), move(debug_info), base_address); | ||||
|         auto debug_info = make<DebugInfo>(make<ELF::Image>(file_or_error.value()->bytes()), m_source_root, base_address); | ||||
|         auto lib = make<LoadedLibrary>(lib_name, file_or_error.release_value(), move(debug_info), base_address); | ||||
|         m_loaded_libraries.set(lib_name, move(lib)); | ||||
| 
 | ||||
|         return IterationDecision::Continue; | ||||
|  |  | |||
|  | @ -134,11 +134,11 @@ public: | |||
| 
 | ||||
|     struct LoadedLibrary { | ||||
|         String name; | ||||
|         MappedFile file; | ||||
|         NonnullRefPtr<MappedFile> file; | ||||
|         NonnullOwnPtr<DebugInfo> debug_info; | ||||
|         FlatPtr base_address; | ||||
| 
 | ||||
|         LoadedLibrary(const String& name, MappedFile&& file, NonnullOwnPtr<DebugInfo>&& debug_info, FlatPtr base_address) | ||||
|         LoadedLibrary(const String& name, NonnullRefPtr<MappedFile> file, NonnullOwnPtr<DebugInfo>&& debug_info, FlatPtr base_address) | ||||
|             : name(name) | ||||
|             , file(move(file)) | ||||
|             , debug_info(move(debug_info)) | ||||
|  | @ -175,8 +175,6 @@ private: | |||
|     // x86 breakpoint instruction "int3"
 | ||||
|     static constexpr u8 BREAKPOINT_INSTRUCTION = 0xcc; | ||||
| 
 | ||||
|     static MappedFile map_executable_for_process(pid_t); | ||||
| 
 | ||||
|     void update_loaded_libs(); | ||||
| 
 | ||||
|     int m_debuggee_pid { -1 }; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling